Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close window in firefox using javascript?

Tags:

javascript

I am using top.window.close() to close the parent window but it is not working in Mozilla firefox.Please suggest alternatives. The above code is working fine for IE6.

like image 201
John Avatar asked Sep 18 '25 03:09

John


2 Answers

From MDC:

This method is only allowed to be called for windows that were opened by a script using the window.open method. If the window was not opened by a script, the following error appears in the JavaScript Console: Scripts may not close windows that were not opened by script.

So if you are trying to open a pop-up window and intending to close it later, you need to do so from JavaScript and not use the target attribute of a link, according to the documentation. However, it seems that windows opened using both target="_blank" and target="foo" actually do close (tried it on Firefox 3.6.13).

However, no matter what you do, you cannot close a window/tab that was opened directly by the user using New Tab/Window (at least under default browser settings).

like image 191
PleaseStand Avatar answered Sep 20 '25 16:09

PleaseStand


Note that you can tell Firefox to allow window.close by setting the dom.allow_scripts_to_close_windows to true in about:config.

The ability to use window.close is further discussed in bug 190515.

like image 21
ArtemGr Avatar answered Sep 20 '25 17:09

ArtemGr