這個答案已經給出,但我會試着解釋我瞭解使用什麼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/ –