I need to close the browser window using the java script.
I have tried using window.close but it is not working.
I have also googled and checked stack overflow for any similar posts. I have also gone through following link but in vain.
Is it possible to close browser window from JavaScript?
What I am trying to do is load a page and on load of the page call a java script method which does window.close
Below is the code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function closeBrowser(){
window.close();
}
</script>
</head>
<body onload="closeBrowser();">
</body>
</html>
It is properly working in IE8 though. Its not working in the fire fox.
And even in IE it gives the alert prompt before actually closing the browser. Can we avoid the alert in IE?
Why it does not work in fire fox?
The reason it was not working in fire fox was due to some settings in the fire fox.
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
window.close is now working in fire fox too.
You have the first script tag twice, which might cause problems. You should also add the attribute type="text/javascript" so that you can be sure that the script is picked up by all browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With