2

As I need JavaScript / jQuery code for closing browser's ( FireFox / Chrome and IE..)

As I have try with window.close().

But it only work for IE.

Is any other way..?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
BJ Patel
  • 6,148
  • 11
  • 47
  • 81

5 Answers5

5

This worked for IE and Chrome. (window.close() worked for IE, then win.close for chrome)

<script type="text/javascript">
    function CloseThis() {
             var win = window.open('', '_self');
             window.close();
             win.close(); return false;
    }
</script>
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
Marco acuna
  • 51
  • 2
  • 1
3

Can check Browser and write respective script for IE / FireFox

IE---->

window.close()

FireFox --->

var answer = confirm("Do you want to close this window ?");
 if (answer){

netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
    window.close();
 }
 else{
     stop;
 }
Pritam Banerjee
  • 17,953
  • 10
  • 93
  • 108
BJ Patel
  • 6,148
  • 11
  • 47
  • 81
2

I don't think that is possible as javascript can only interact with the pages rendered by the browser, not the actual browser.

gion_13
  • 41,171
  • 10
  • 96
  • 108
2

Windows can only be closed by scripts (window.close()) that were opened by scripts in the first place. So generally, this isn't possible (https://developer.mozilla.org/en/DOM/window.close)

mmcnickle
  • 1,599
  • 10
  • 13
0

Try this snippet

window.close()
Andreas Eriksson
  • 8,979
  • 8
  • 47
  • 65
  • 2
    From [Mozilla](https://developer.mozilla.org/en/DOM/window.close): "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." – Dennis Sep 23 '11 at 13:30