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 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.
https://developer.mozilla.org/En/DOM:window.close
To get around this problem we will have to fool the firefox to thin it window is opened by window.open
We can use this code
<script>
function closeMe()
{
var win=window.open("","_self");
win.close();
}
</script>
<html>
<body>
<form>
<input type="button" name="Close"
onclick="closeMe()" />
</form>
</body>
</html>
We can also write script like this
function winClose()
{
window.top.opener=null;
window.close();
}
or
function closeWindow()
{
window.open('','_parent','');
window.close();
}
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 asp.net and C# c-sharp
3. Disable browser back button functionality using javascript in ASP.NET
Mozilla Firefox JavaScript Window.Close() Not Working
Posted by
Unknown
If you like this post than join us or share
Labels: ASP.NET, JavaScript
Subscribe to:
Post Comments (Atom)
18 comments:
Hi
This is praveen.It is more helpful to me.Thanx
Hi,
Is there a way we can enforce this configuration thru Java Script for Mozilla?
Option: "dom.allow_scripts_to_close_windows" is true
- Suneel
@suneel:
You can try this code instead
function closeWindow() {
netscape.security.PrivilegeManager.enablePrivilege(”UniversalBrowserWrite”);
alert(”This will close the window”);
window.open(”,’_self’);
window.close();
}
Hope this helps
yes this is 100% working in Mozilla. Thanks Buddy!
how to refresh a dropdown list,when we refresh the page???????????
help me in js
Hi , I am getting this error
A script from "http://localhost" was denied UniversalBrowserWrite privileges.
for the code :
function closeWindow() {
netscape.security.PrivilegeManager.enablePrivilege(”UniversalBrowserWrite”);
alert(”This will close the window”);
window.open(”,’_self’);
window.close();
}
Any suggessions
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.
not work in mozila
Hi,
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?")) {
close();
}
if (confirm("Do You Want To Exit?")) {
close();
}
we can above function to close the window.
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.
Cheers
Marcos
Unable to work in Firefox..
Thanks
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.
thank a lot for this tip!
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?
Hi
This is rama.It is more helpful to me.Thank you so much.
MohanRaj
Thanks a lot its working.. amazing.
Post a Comment