history.pushstate jquery后退按钮未加载prev内容

时间:2014-10-09 11:18:28

标签: javascript jquery browser-history

我正在尝试implement history.pushstate with jQuery as described

这是我的以下代码:

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);
  }
});

地址栏正在拾取正确的地址,但是当我点击后退按钮时,地址栏会正确返回,但之前的内容未加载

0 个答案:

没有答案