这个答案已经给出,但我会试着解释我了解使用什么pushState的 考虑您的网址是“google.com/gmail”
词根记忆CURRENTURL为临时URL,所以您的浏览器将显示此URL。在这一步中,堆栈中会有一个URL,即google.com/gmail#!/tempURL
。
history.replaceState(null, document.title, location.pathname+"#!/tempURL");
2.Push的previousURL作为新的国家所以现在你的浏览器将显示previousURL即google.com/gmail
。
history.pushState(null, document.title, location.pathname);
堆栈的当前状态
第一个元素: google.com/gmail
最后元件: google.com/gmail#!/tempURL
3.Now添加监听器来监听事件
window.addEventListener("popstate", function() {
if(location.hash === "#!/tempURL") {
history.replaceState(null, document.title, location.pathname);
//replaces first element of last element of stack with google.com/gmail so can be used further
setTimeout(function(){
location.replace("http://www.yahoo.com/");
},0);
}
}, false);
这个问题应该提供一个答案:http://stackoverflow.com/questions/6359327/detect-back-button-click-in-browser – thomasfedb
歌剧没有按发送onbeforeunload事件 – Dimitar
查看Ben Alman的JQuery BBQ。 BBQ代表后退按钮和查询库。 http://benalman.com/projects/jquery-bbq-plugin/ –