If you are developing a ASP.NET application and have written a javascript
to close browser window using window.close
this won't work in Mozilla firefox
And 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
![]() |
||
|
|
![]() |
|
Mixx it!
|
add to del.icio.us saved by 0 users |











3 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
Post a Comment