Open
Bug 165418
Opened 22 years ago
Updated 2 years ago
|window.opener.closed| errors if the window's opener is already closed
Categories
(Core :: DOM: Core & HTML, defect, P5)
Tracking
()
NEW
People
(Reporter: budingraham, Unassigned)
Details
If I test to see if a window's opening window still exists by testing window.opener.closed, and the opening window is already closed, this command will hang the current window.
Comment 2•22 years ago
|
||
Browser, not engine ---> DOM Level 0 We need a reduced testcase. Bud, if there is a small testcase, could you paste the HTML here via the Additional Comments box? The alternative would be to attach the parent and child HTML files separately via the "Create a New Attachment" link above. But I'm guessing your testcase is small enough to paste the HTML for both right here, in-line.
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
OK, here are the test files that you need. This is quite a simple test. First using the ParentWindow.html use the button to create the child window. Manually close down the Parent window once the Child window is created. Lastly, try to close the Child window using the button on it. The window will not close - it will in IE6 and NS4. Thanks for looking into this. Please also refer to the comments that I made in the ChildWindow.html ParentWindow.html <html> <head> <script language="Javascript"> <!-- function openChildWindow() { hWndAccess = window.open( 'ChildWindow.html', '','resizable,scrollbars,status' ); } //--> </script> </head> <body> <form name="frmMain"> <input type="button" value="Open Child Window" onClick="openChildWindow();"> </form> </body> </html> ChildWindow.html <html> <head> <script language="Javascript"> <!-- function closeDown() { // *** This 'if' statement will stop Mozilla in its tracks. // *** The window.close(); line below will never execute, // *** nor will the alert come up. if( window.opener.closed ) { alert( 'I got here.' ); } // *** This following code will work in Mozilla, but not in IE6 or NS4 /* if( !window.opener ) { alert( 'I got here.' ); } // *** The following code needs to be coded for all three to work. // *** Old code written before using just 'window.opener.closed' // *** just won't work until someone goes and recodes the pages. if( !window.opener || window.opener.closed ) { alert( 'I got here.' ); } */ window.close(); } //--> </script> </head> <body> <form name="frmMain"> <input type="button" value="Close Child Window" onClick="closeDown();"> </form> </body> </html>
Comment 4•22 years ago
|
||
Following the steps to reproduce that Bud gave in Comment #3, I get this error in Tools > Web Development > JavaScript Console: Error: window.opener has no properties Source File:file:///(path to)/ChildWindow.html Line: 11 I'm going to change the summary from: |window.opener.closed| hangs if the window's opener is already closed to: |window.opener.closed| errors if the window's opener is already closed because the browser doesn't hang. I'm still able to resize the browser window, etc., and my CPU stays at 1-2%. The reason that you're not seeing the following alert() come up: if( window.opener.closed ) { alert( 'I got here.' ); } is not because the browser is hanging. It's because |window.opener| is evaluating to |null|, hence the above syntax error when trying to access |window.opener.closed| : |null| doesn't have any properties. Once a run-time JS error occurs in Mozilla, all JS stops executing. That's why the alert doesn't come up - So it boils down to a question for the DOM folks: how are users supposed to use the test the |closed| property of |window.opener|? Should it be done as Bud has indicated in his comments to ChildWindow.html? if( !window.opener || window.opener.closed ) { etc. }
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: window.opener.closed hangs if the window's opener is already closed → |window.opener.closed| errors if the window's opener is already closed
Comment 5•22 years ago
|
||
typo above: supposed to use the test the |closed| property should be supposed to test the |closed| property
Comment 6•22 years ago
|
||
So... why the use of .closed? This lives on nsIDOMWindowInternal, so it's very definitely not for public consumption...
Comment 7•22 years ago
|
||
window.closed is a DOM0 property, so it *is* intended for public usage, at least from JS (not sure why it lives in the _internal_ interface though, but so does a lot of other DOM0 properties).
Comment 9•21 years ago
|
||
If, as Phil states, window.opener is evaluating to 'null' when the parent window is closed, why does (typeof window.opener) still evaluate to 'object'? This is a most inconvenient bug. How else can we test if the opener is closed? Is (!window.opener) a reliable alternative? What is (!null) anyway? I'm using 7.02 on Windows XP.
Comment 10•21 years ago
|
||
typeof(null) is "object" in ECMAScript, as you could check directly in any browser. (!null) tests true in ECMAScript (again, in all browsers).
Comment 11•21 years ago
|
||
not sure if it's related, but if the parent window changes location (eg. goes to a new webpage), the child window loses all permissions to access (even read permissions) the parent window's properties. Is it possible to grant access to properties that don't threaten security? (namely window.closed)
Comment 12•21 years ago
|
||
this seems the be the same problem i'm having atm. see the URL i added ( http://www.tqsoft.de/playground/ ). (when reloading the page you get the opener object alerted, when closing the browser window a popup should appear that checks if the main window exists, which fails in mozilla) i tried to check window.opener.closed, but i get an error because the window.opener object is killed when closing the window.
Updated•15 years ago
|
Assignee: general → nobody
QA Contact: desale → general
Comment 13•6 years ago
|
||
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046 Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5. If you have questions, please contact :mdaly.
Priority: -- → P5
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•