Mozilla Firefox JavaScript Window.Close() Not Working

Mozilla firefox JavaScript window.close() not working, If you are developing a ASP.NET application and have written javascript to close browser window using window.close, this won't work in Mozilla firefox

The reason for this is, This method is only allowed to be called for windows that were opened by a script using the 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.

To get around this problem we will have to fool the firefox to thin it window is opened by

We can use this code


function closeMe()

<input type="button" name="Close"
onclick="closeMe()" />
We can also write script like this
function winClose()


function closeWindow()

if it doesn't works

please set your firefox browser:

1.input "about:config " to your firefox address bar and enter;

2.make sure your "dom.allow_scripts_to_close_windows" is true

Related Posts:

1. Disable copy paste cut and right click in textbox on aspx page using javascript

2. Highlight gridview row on mouse over using javascript in and C# c-sharp

3. Disable browser back button functionality using javascript in ASP.NET
If you like this post than join us or share


praveen said...

This is praveen.It is more helpful to me.Thanx

Suneel said...


Is there a way we can enforce this configuration thru Java Script for Mozilla?
Option: "dom.allow_scripts_to_close_windows" is true

- Suneel

amiT jaiN said...


You can try this code instead

function closeWindow() {”UniversalBrowserWrite”);
alert(”This will close the window”);”,’_self’);

Hope this helps

Muhammad said...

yes this is 100% working in Mozilla. Thanks Buddy!

Anonymous said...

how to refresh a dropdown list,when we refresh the page???????????
help me in js

Anonymous said...

Hi , I am getting this error
A script from "http://localhost" was denied UniversalBrowserWrite privileges.

for the code :

function closeWindow() {”UniversalBrowserWrite”);
alert(”This will close the window”);”,’_self’);

Any suggessions

Anonymous said...

It wokrs in Firefox but doesn't work in IE .
so please provide me a code that works for both IE & Firefox.

Thx in advace.

Anonymous said...

not work in mozila

David George said...


Thanks for the 'about:config' advice; this is the first post about this problem that I've found to actually work.


Thanks for ur help
Other wise we can use the following function which prompts the user to close or not.

if (confirm("Do You Want To Exit?")) {

Anonymous said...

if (confirm("Do You Want To Exit?")) {

we can above function to close the window.

Anonymous said...

that works mate, 50 sites and you got it spot on. Well done, thanks a lot.

about:config and there it was, the thing was false.


Anonymous said...

Unable to work in Firefox..


Anonymous said...

Not a single idea suggested in the entirety of this article nor any permutation thereof came anywhere near working. I want 20 minutes of my life back.

idontknow said...

thank a lot for this tip!

Anonymous said...

Great post..!

Nice to know stuff like "about:config".

Would be awesome to know how to change the setting "dom.allow_scripts_to_close_windows" through script. Any thoughts?

rama said...

This is rama.It is more helpful to me.Thank you so much.

Anonymous said...


Thanks a lot its working.. amazing.

Find More Articles