[英]"beforeunload" event not firing on Google Chrome for popup window
當用戶關閉第二個窗口時,我需要運行一些代碼:
var win = window.open("chat-box", null, "height=600,width=1300,status=yes,toolbar=no,menubar=no,location=no");
if(win != null)
{
win.addEventListener("beforeunload", function()
{
console.log("It closed");
});
}
它適用於 Firefox,但不適用於 Google Chrome。
關於為什么或如何解決它的任何想法?
我過去使用的一種方法是使用間隔計時器來檢查win.closed
if(win){
let timer = setInterval(()=>{
if(win.closed){
console.log('It closed')
clearInterval(timer)
}
}, 1000);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.