window.close() does not close iframes




12 years ago
7 years ago


(Reporter: danswer, Unassigned)


Firefox Tracking Flags

(Not tracked)



(1 attachment, 1 obsolete attachment)



12 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070508 Firefox/
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070508 Firefox/

If dom.allow_scripts_to_close_windows has been set in prefs.js or via about:config then window.close() should close the indicated window.  And this is fine.

However, in the case of an iframe it does nothing.
What it should do (I think) is to remove the iframe element, just as it would close a tab or browser window when executed at the top level (hence removing those elements).

Csaba Gabor from Vienna

Reproducible: Always

Steps to Reproduce:
<body onload="window.setTimeout('loaded()',2000)">
The alert shouldn&#39;t appear,
and the iframe should disappear
<script type='text/javascript'>
function loaded() {
  var src = "javascript: \
     document.write('Src modified'); \
     document.close(); \
     window.close(); \
     window.alert('Iframe should\\'ve closed')";
  myframe = document.getElementById('foo');
  myframe.src = src;
<table border><tr><td>Hi</td></tr>
<iframe id=foo
  src="javascript:'Init\x27l frame'">

Comment 1

12 years ago
Same code as in initial report.
The alert should not be possible if the iframe had closed
(and also, the iframe should no longer be there to be seen).

Comment 2

12 years ago
Does iframe.close() do that in any other browser?  Why not just remove it from the DOM using removeChild?

Comment 3

12 years ago
(In reply to comment #2)
> Does iframe.close() do that in any other browser?

No, as far as I know.  I only have IE 6 to check it with.

> Why not just remove it from the DOM using removeChild?

For same domain origin, that's fine, of course.
I am more concerned with the general cross domain situation.


Comment 4

12 years ago
Sorry, looks like I selected the wrong content type earlier.
Attachment #279081 - Attachment is obsolete: true

Comment 5

12 years ago
IMO, if the parent page is in another domain, you shouldn't be able to remove the iframe from the parent page's DOM.  That could confuse the parent page.  about:blanking the iframe would be ok, though.

Comment 6

11 years ago
I //think//this may be the same problem. Not sure, but I will post if here.

“Close Window” (javascript:window.close())button does not work on sub-pages in Seamonkey browser

Seamonkey 1.1.7/1.1.8
Windows XP Professional SP2

In some pages, such as any camera page at the following example link:, when the sub-page/insert/next window is opened, the Close Window button does not work. The button is supposed to invoke “javascript:close()”
I also have a similar problem at my bank logon site where Close Window (javascript:window.close() does not close secondary windows.

Below, two Seamonkey newsgroup members have verified this problem and found a work-around.

Peter Potamus wrote:
it took me a while, cause mine was opening within the same tab, which doesn't close.  So I made a change, to open it in a new tab, and it works.  The change I made is: Edit, Preferences, Navigator, Tabbed Browsing, near the bottom it says "Open links meant to open a new window in" and I used "a new tab in the current window," or "a new window" both work.

NoOp wrote:
My settings are always set to open in a new tab, so perhaps that's why I
didn't have the problem from the start. I just turned mine off and set
to "The Current Tab Window" and found that I couldn't close the window
from the "Close Window" button on the camera page. So that definately
looks like it's the problem. Looks like a bug to me... 
Per HTML, only top-level browsing contexts can be closed.
Last Resolved: 7 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.