BJ Patel
BJ Patel

Reputation: 6268

JavaScript/ jQuery for Closing Browser FireFox / Chrome / IE

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..?

Upvotes: 2

Views: 26220

Answers (5)

BJ Patel
BJ Patel

Reputation: 6268

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;
 }

Upvotes: 3

Marco acuna
Marco acuna

Reputation: 51

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>

Upvotes: 5

mmcnickle
mmcnickle

Reputation: 1607

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)

Upvotes: 2

gion_13
gion_13

Reputation: 41533

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

Upvotes: 2

Andreas Eriksson
Andreas Eriksson

Reputation: 9027

Try this snippet

window.close()

Upvotes: 0

Related Questions