Page 1 of 1

Mozilla 1.2 - Closed Window Loses Properties

Posted: Mon Oct 27, 2003 4:52 pm
by Roger Bailey
Hi, First Post!

For some time I have been using the following script to close child windows when the parent window disappears. It worked fine in Moz 0.9 and various IE versions.

Code: Select all

function checkParent()
{
  if (window.opener)
  {
    if (window.opener.closed)
    {
      window.close();
    }
  }
}
var checkParentIntervalID = window.setInterval("checkParent()", 500);
Having gone throug some recent upgrading I now find that it does not work in Moz 1.2 on Linux or Mac. In the Javascript Console I get the message 'window.opener has no properties'.

It seems that when the parent window is closed is destroying the properties it's window object. Formerly the boolean value window.closed was preserved and set to true.

Q1. Is this a genuine bug? I searched Bugzilla (horrible form) but could not any reference.

Q2. Is there a work arround? I have tried

Code: Select all

if (typeof(window.opener.closed) == undefined) ...
but this just throws the same error.

Many Thanks,

Solution

Posted: Fri Oct 31, 2003 11:21 pm
by Roger Bailey
OK. Here is the solution to the 'Closed Window Properties Bug'.

Code: Select all

function checkParent()
{
  var isClosed = true;
  for (var i in window.opener) {
    if (i == "closed") {
      if (!window.opener.closed) {
        isClosed = false;
      }
      break;
    }
  }
  if (isClosed) {
    window.close();
  }  
}

// Start the check parent interval timer.
var checkParentIntervalID = window.setInterval("checkParent()", 500);
Iterate over the propeties of window.opener. If the property closed does not exist assume window has been closed, otherwise test for true to decide if window is closed.