From JavaScript version 1.1 onwards, a window object may persist after it has been closed. This may seem odd but it is possible that the window object will have had other object references added to it and for it to be deleted, it must relinquish those references. Without this object persistence, a dangerous cascading delete effect may happen, inadvertently discarding all manner of objects within your script context.
The only valid thing you should access at this point is the closed property. This allows you to check for the window having been closed by the user before you try to do something with it.
Some programmers would argue that this is poor technique anyway and that a reference to a window held externally should be nulled by the closing function. That way you can test a variable that exists within the script's scope chain rather than an object that should probably have been purged from memory. Given the bugs in the implementation of this feature, that is a better way to determine whether a window is still in existence.
This value can be read by an unsigned script in another window. However, Netscape Navigator (at least on the Macintosh platform) exhibits some bugs with this whole mechanism and the property value is of limited use in any case.
For a start, you cannot access the closed property of the object that the Window.open() method returns because it is an EventCapturer object and not a window object. You can contrive to store a reference to the new window in the original window's properties by making it pass a reference to its window.self property which needs to be stored in a property belonging to its window.opener. However, if the child window is then closed, the object that refers to it becomes void and there is no access to any of its properties, let alone its window.closed property.
There are sufficient problems in this area that without some quite tricky scripting you cannot make use of this facility in a portable manner.
See also: | Frame object, Window object |
Prev | Home | Next |
Window.close() | Up | Window.confirm() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |