views:

410

answers:

4
window.close();

The above will pop up a confirm dialog each time,and not working at all in firefox.

+2  A: 

I think that's not without a reason. People don't like windows being closed without notice.

Ikke
A: 

Windows not opened by JavaScript cannot be automatically closed with JavaScript (and I can't think of any good reason for a website to close the window that the visitor arrived at the site with, discarding their Back history in the process)

David Dorward
+2  A: 

Closing a browser window is not as straight-forward as it used to be years ago.

Typically, a newly opened window can be closed if:
1. the 'close' is called within the DOM of the window itself
2. the closer is the opener

However, with almost all browsers having tabs, if the opened window is the only remaining tab in the main window, it might not close without prompt for above case 1. Even if it closes, it might just close the tab and leave the main window opened.

o.k.w
+1  A: 

You can't - it's a security feature. You'll need to look into showing some form of modal dialog if you wish to be able to close it. Have a look at something like This JQuery Example which features auto-close

Katy