使用ajax加载内容时如何处理浏览器后退/下一步按钮?

时间:2014-10-10 09:27:50

标签: javascript jquery ajax

我尝试过BBQ和history.pushstate,但两者都有问题。在history.pushstateusing bbq

的堆栈中查看我的其他问题

使用此代码,我基本上在特定div中加载内容,每次单击链接时替换旧内容。我正在尝试在加载内容时更改浏览器地址,并且能够点击浏览器本身的后退或上一个按钮来重新加载内容

divheight = $(".heightDiv").innerHeight();
container = $(".loadContent");
currentItem = null;
$(".list-group a").each(function () {
    var item = $(this);
    if (item.hasClass("active")) {
        currentItem = item;
    }
    item.on("click", function() {
        $(".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();
        });
    });
});

0 个答案:

没有答案