簡體   English   中英

“beforeunload”事件不會在谷歌瀏覽器上觸發彈出窗口

[英]"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.

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