Close the parent window in fireFox

Is it possible to close parent window in Firefox 2.0 using JavaScript. I have a parent page that opens another window, I need to close the parent window after 10 seconds. I've tried Firefox tweaks "dom.allow_scripts_to_close_windows", tried delay but nothing works.

Any help would be really appreciated.

thank

+1


source to share


3 answers


Edited from quirksmode (EDIT: added a little context as suggested by Diodeus):

In theory

opener.close()

      

should be the code from the popup: close the window that opened that popup.



However, in some browsers it is forbidden to automatically close windows that were not opened by JavaScript. The line above works fine in Explorer on Mac, Mozilla, Opera and OmniWeb, but not in Explorer on Windows, Netscape 4 and below, and iCab. In these browsers, the user is prompted to confirm closing the window. As far as Safari is concerned, it does absolutely nothing.

Rather to my surprise, it is very easy to bypass this confirmation field in Explorer 5.5 and 6 on Windows. Explorer just looks to see if the page has an opener. If the window is not opened by the user and cannot be closed without confirmation. So we need to do an Explorer trick to think that the opening page has an opener:

opener.opener = top; // or whatever, as long as opener.opener has a value;
opener.close()

      

This trick does not work in Netscape 4 and below and iCab, these browsers have more sophisticated ways to determine if a JavaScript window has been opened.

+3


source


Using only the opening object may not always close the parent window for security reasons. What can you do:

There is a function on the parent named closeWindowFromChild ():

function closeWindowFromChild ()
{
    this.window.close ();
}


On the child when you want to close the window:

function closeParentWindow ()
{
    opener.closeWindowFromChild ();
}

And that should work fine.: - D

+5


source


Generally, you cannot close a window that you have not opened using javascript.

+2


source







All Articles