views:

2735

answers:

3

Is it possible to close parent window in Firefox 2.0 using JavaScript. I have a parent page which opens another window, i need to close the parent window after say 10 seconds. I have tried Firefox tweaks "dom.allow_scripts_to_close_windows", tried delay but nothing seems to work.

Any help will be really appreciated.

Thanks

+1  A: 

Generally, you can't close a window which you didn't open yourself using javascript.

Gareth
+3  A: 

Scissored from quirksmode (EDIT: added a bit of context, as suggested by Diodeus):

Theoretically

opener.close()

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

However, in some browsers it is not allowed to automatically close windows that have not been 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 lower and iCab. In these browsers the user is asked to confirm the closing of the window. As to Safari, it does absolutely nothing.

Rather to my surprise it's very easy to get around this confirm box in Explorer 5.5 and 6 on Windows. Explorer merely looks if the page has an opener. If it doesn't the window has been opened by the user and may not be closed without a confirm. So what we need to do is trick Explorer into thinking the opening page has an opener:

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

This trick doesn't work in Netscape 4 and lower and iCab, these browsers have more sophisticated ways to determine whether a window has been opened by JavaScript.

I think you should add the preceding and trailing paragraphs to add context to this code snippit.
Diodeus
Thanks it worked but i had to change dom.allow_scripts_to_close_windows" setting
rsapru
Seems like this only works for Firefox 3.0 and not with Firefox 2.0
rsapru
+4  A: 
Pedrin