簡體   English   中英

如何捕獲IE8中的后退按鈕單擊事件?

[英]How to capture back button click event in IE8?

當用戶單擊瀏覽器的后退按鈕時,我正在嘗試執行功能。 對於chrome&firefox,我已經通過html5“ popstate”事件實現了它。 我無法捕獲IE8中的后退按鈕單擊事件。 就我而言,即使url / location哈希值沒有變化,我也需要捕獲后退按鈕的click事件。 有人幫忙嗎??

  window.onbeforeunload = function (e) {
        var e = e || window.event;
        var msg = "Do you really want to leave this page?"
        // For IE and Firefox
        if (e) {
            e.returnValue = msg;
        }
        // For Safari / chrome
       return msg;
     };

好吧,從google搜索中我找到了此鏈接 ,看來您可以區分刷新和單擊返回:

window.onunload = function(e) {
// Firefox || IE
e = e || window.event;

var y = e.pageY || e.clientY;

if(y < 0)  alert("Window closed");
else alert("Window refreshed");

}

event.pageY | event.clientY :檢測鼠標的位置。
window.onunload :負責在關閉頁面時執行指令。

我自己沒有嘗試過,但希望這會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM