Search code examples
javascriptinternet-explorer-9window.openwindow.closed

window.closed IE9 reporting true when window is still open


UPDATE 2012-01-10
the popup URL is in another domain as the parent window, which appears to be the issue! How can I solve it?

I'm using the following code to detect whether the popup window is closed. It works fine in Firefox 8 and Chrome but doesn't function as expected in IE9. In IE9 the alert with "true" shows already when the popup is still open. How come IE9 has a reference to the window and the closed property reports true when the window is still open? And how can I fix it?

Javascript

var dialogWindow;
var dialogTimer;
function openDialog(url, name, options) {
 dialogWindow = window.open(url, name, options);   
 dialogTimer = setInterval(function() {   
  if(dialogWindow.closed) // IE9 reports true and executes function
  {  
   alert(dialogWindow.closed); // alert with "true"
   clearInterval(dialogTimer);  
   window.location.reload();  
  }  
 }, 2500);

 if (dialogWindow && dialogWindow.focus) 
  dialogWindow.focus();     
}

UPDATE I also tried the following approach, which shows the exact same behaviour in IE9

var dialogWindow;
var dialogTimer;
function openDialog(url, name, options)
{
    dialogWindow = window.open(url, name, options);   
    dialogTimer = setInterval("checkDialogOpen()", 2500);

    if (dialogWindow && dialogWindow.focus) 
        dialogWindow.focus();     
}

function checkDialogOpen()
{
    if(dialogWindow.closed) 
    {  
        alert(dialogWindow.closed);
        clearInterval(dialogTimer);  
        window.location.reload();  
    } 
}

Solution

  • From what I can tell, this is a bug in IE9.

    http://support.microsoft.com/kb/241109