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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With