2016-01-22 114 views

回答

0

沒有,一旦調用這個代碼

document.location.href = "http://my.domain" 

沒有辦法攔截(由intercept假設你的意思stopping it from happening)這一呼籲。

可以趕上然而事件unload

window.addEventListener('beforeunload', function(event) { 
    console.log('I am the 1st one.'); 
    }); 
    window.addEventListener('unload', function(event) { 
    console.log('I am the 3rd one.'); 
    }); 
0

在舊的瀏覽器,這是不可能的。但是,使用HTML5,您可以使用service workers,它允許您攔截通信(允許您執行諸如爲用戶提供離線體驗之類的操作)