WelcomeTo
WelcomeTo

Reputation: 20591

Closing current window don't work in FF 3.6 and Chrome

How to close current window in chrome and FF? I try to close window using following native JavaScript code :

win = top;
win.opener = top;
win.close();

and

window.open('', '_self', '');
window.close();

and

$wnd.close(); 

All dont work in Chrome and FF. In IE7 it work (but not with all code remembered above).

Upvotes: 0

Views: 286

Answers (2)

mplungjan
mplungjan

Reputation: 178375

The close that works in IE is a hack and cannot be relied on.

Do not try to close people's main browser window under any circumstances. They lose their history and is considered Denial of Service.

If you are on an intranet and can control the browser, use HTA for IE or implement @Hello's suggestion which relies on a certificate and will not work in other browsers than Mozilla/Netscape, I do not even know if it still works in Firefox.

Perhaps you tell us WHY you want to close the window and we can surely come up with several alternatives

Upvotes: 1

Jama A.
Jama A.

Reputation: 16099

Try using something like this:

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
window.open('', '_self', '');
window.close();

Upvotes: 0

Related Questions