Mozilla 1.2 - Closed Window Loses Properties

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Roger Bailey
Forum Newbie
Posts: 3
Joined: Mon Oct 27, 2003 4:52 pm
Location: Cape Town, South Africa

Mozilla 1.2 - Closed Window Loses Properties

Post 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,
Roger Bailey
Forum Newbie
Posts: 3
Joined: Mon Oct 27, 2003 4:52 pm
Location: Cape Town, South Africa

Solution

Post 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.
Post Reply