I need to know when a window is closed by the user.
I use the javascript property Window.closed. This code is working perfectly for all websites, except when I load facebook.com in the window. I get that the window is closed as soon as the DOM is loaded.
Has Facebook done something specific so we can't use the closed property ? Do you think I can do something ?
<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>
Thanks for your help.