Closed
Bug 207267
Opened 21 years ago
Closed 21 years ago
top.opener.close() does not close parent window
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
VERIFIED
DUPLICATE
of bug 183697
People
(Reporter: tobyg, Unassigned)
Details
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.3.1) Gecko/20030425 Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.3.1) Gecko/20030425 I have an html page that contains the following Javascript to open a new window: <script LANGUAGE="JavaScript"> <!-- // The following Javascript is for use within a window that will open a new // window with the Javascript window.open() function. var lastNewWindow = null; function displayNewWindow(pageName, width, height, url, scrollable, resizable, toolbar, win) { if (typeof win == "undefined" || typeof win == "unknown") win = lastNewWindow; if (!isWindowClosed(win)) win.focus(); win = window.open('', pageName, 'width=' + width + ',height=' + height + ',scrollbars=' + scrollable + ',resizable=' + resizable + ',toolbar=' + toolbar); win.focus(); win.location.replace(url); return (lastNewWindow = win); } // Cover all bases for platforms function isWindowClosed(win) { return (typeof win == "undefined" || typeof win == "unknown" || win == null || typeof win.document == "undefined" || typeof win.document == "unknown" || win.document == null); } //--> </SCRIPT> <script LANGUAGE="JavaScript"> <!-- displayNewWindow('TestPage', 800, 600, 'page2.html', 'yes', 'yes', 'no', null); //--> </SCRIPT> (I know it seems strange to have two <SCRIPT> blocks, but it is because the page contents are dynamically generated.) The opened web page (page2.html) contains the following Javascript to close the first page (i.e. the opener): <script LANGUAGE="JavaScript"> <!-- top.opener.close(); //--> </SCRIPT> However, the first page is NOT closed. Looking at the JavaScript console, it has the following error message: Scripts may not close windows that were not opened by script. Note that this worked in Mozilla 1.2b. Not sure about 1.3. Reproducible: Always Steps to Reproduce: 1. Create web page that contains Javascript window.open() call to open a second page in a new window. 2. In the second page, have top.opener.close() Javascript command. 3. Bring up the first page in Mozilla; it should open the second page and then the original page should be closed. Actual Results: The second page is opened in a new window as it should be, but the top.opener.close() does NOT work and the first window remains open. Expected Results: The first window should be closed when the second window is opened.
Comment 1•21 years ago
|
||
Toby, the JavaScript console is correct, although maybe a bit brief. If a user opened a window, that window cannot be closed by a script. If a script opens a window, that window can be closed with .close() There was a bug with this before, fixed with bug 32571. See bug 183697 for further discussion. *** This bug has been marked as a duplicate of 183697 ***
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → DUPLICATE
Updated•20 years ago
|
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•