在浏览器上按回按钮返回历史记录URL

时间:2013-12-23 08:39:14

标签: php jquery html5 browser-history

我正在使用

  

window.history.pushState

和popstate函数,用于在单击浏览器的后退按钮时获取上一页URL,并且我想在每个popstate函数调用时重新加载页面。

我的代码是..

function refresh_results() {
    page_link = $("#form").serialize();
    if(page_link!=window.location){
            window.history.pushState({path:pageurl},'',pageurl);

        }
}

在popstate函数中

$(document).ready(function($) {
   var popped = ('state' in window.history && window.history.state !== null), initialURL = location.href;
    if (window.history && window.history.pushState) {
        $(window).bind('popstate', function(e) {
            var initialPop = !popped && location.href == initialURL;
            popped = true;
            if (initialPop) return;
            pageurl = location;
            console.log(pageurl);
            window.location = location.href;
            //window.location = pageurl;
            return e.preventDefault();

        });
  }
});

但是,每次点击后退按钮页面时,我都会在Chrome中连续刷新,但是在Firefox中它很好。 你可以告诉我我的功能如何可行,并建议我,如果我错过任何东西

0 个答案:

没有答案