问题
I am trying to implement history.pushstate with jQuery as described
This is the following code I have:
container = $(".loadContent");
currentItem = null;
$(".list-group a").each(function (index) {
var item = $(this);
if (item.hasClass("active")) {
currentItem = item;
}
item.on("click", function(e) {
e.preventDefault();
history.pushState({}, '', $(this).attr("href"));
$(".heightDiv").css("height", divheight);
if (currentItem == item) return;
$(".content").empty();
$(".loading").css("height", divheight).show();
url = this.href + " .content";
if (currentItem) currentItem.removeClass("active");
currentItem = item.addClass("active");
container.load(url, function(){$(".loading").hide();});
return false;
});
});
loadPage = function(href) {
container.load(href + " .content");
};
$(window).on("popstate", function(e) {
if (e.originalEvent.state !== null) {
loadPage(location.href);
}
});
The address bar it is picking up the correct address, however when I hit the back button, the address bar gets back correctly but the previous content it is not loaded
来源:https://stackoverflow.com/questions/26277054/history-pushstate-jquery-back-button-not-loading-prev-content