Link to home
Start Free TrialLog in
Avatar of jeesrinu
jeesrinu

asked on

How to close a window in javascript(Mozilla)

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

Avatar of Barry Jones
Barry Jones
Flag of United Kingdom of Great Britain and Northern Ireland image

"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
Avatar of -null-
-null-

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?
ASKER CERTIFIED SOLUTION
Avatar of Barry Jones
Barry Jones
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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/
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

Avatar of jeesrinu

ASKER

It is not working in mozilla