How to close a window in javascript(Mozilla)

jeesrinu
jeesrinu used Ask the Experts™
on
Hi,

i am using below code to close the window in javascript. It is working in IE .But it is not working in Firefox version 3.5.3 .

  Anybody please tell the solution how can i made changes to my code to work in mozilla.

Thanks in Advance.


<html>
<body bgcolor="#FFFFFF">
<a href="javascript:window.close();">Close This Window</a>
<br>
<form>
<input type=button value="Close This Window" onClick="javascript:window.close();">
</form> 
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
"This method is only allowed to be called for windows that were opened by a script using the window.open method."

Quote from mozilla: https://developer.mozilla.org/en/DOM/window.close

Commented:
Hi

That is the correct command, so it's quite possible that it is blocked for security purposes.  Normally you can only close a window which you opened in your code, else the user gets a prompt saying that the program is requesting a window close.  Is it a window your code has opened, or is it the main browser window?
If your window was originally opened by another, then from that "parent" page you can close the window via a reference:
var o_win = window.open("http://www.google.com");
 
// Then..
o_win.close();

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
you can take a look at it from the simple code in my blog. you also will not see the yes or no option when you close with this method.
http://kadirselcuk.wordpress.com/2009/04/14/close-current-window-or-parent-window-in-javascript-without-that-ugly-confirm-prompt/

Commented:
try with only window.close()


<html>
<body bgcolor="#FFFFFF">
<a href="#" onclick="window.close();">Close This Window</a>
<br>
<form>
<input type=button value="Close This Window" onClick="window.close();">
</form> 
</body>
</html>

Open in new window

Author

Commented:
It is not working in mozilla

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial