0

我需要知道用户何时关闭窗口。

我使用 javascript 属性Window.closed。此代码适用于所有网站,除非我在窗口中加载 facebook.com。我知道一旦加载 DOM,窗口就会关闭。

Facebook 是否做了一些特定的事情,所以我们不能使用封闭的财产?你觉得我能做点什么吗?

<html>
  <head><title>Popup</title></head>
  <body>

    <input type="button" id="openPopupWorking" onclick="popup('https://www.wikipedia.org');" value="Open Popup Wikipedia" />
    <input type="button" id="openPopupNotWorking" onclick="popup('https://www.facebook.com/Starbucks/');" value="Open Popup Facebook" />

    <script type="text/javascript">

      function popup(SiteUrl) {
    
      var myWindow=window.open(SiteUrl,'newWindow','width=900,height=900');
    
            //Check if the popup is closed by the user ! Don t work with Facebook 
            var timer = setInterval(function () { 
                if (myWindow && myWindow.closed===true) { 
                    alert('Popup is closed')
                    clearInterval(timer);
                }
                
            }, 1000);
    
        }
    </script>
  </body>
</html>

谢谢你的帮助。

4

0 回答 0