Home | All Questions | alt.html FAQ > Client-side Windows Scripting

How do I close a window without the confirmation box popping up?

If you do not own the window in question, then you cannot close it without a confirmation box appearing. This is a security feature of Javascript, else we would have too many malicious Javascripts closing all the windows on a person's desktop.

To "own" a window your site would have to have created that window. Then you can close this window without the confirmation box with window.close();

Renaming a window with window.name (writeable in Javascript 1.1) is not enough to grant ownership of that window to you.The solution would be to start your site off in a freshly created window and call window.close(); at the end. This is pretty much the only way to claim ownership, but some may find it annoying that your site demands to open in its own window: If users can access the site at any point along the way, you will have to add a Javascript to check whether the window in which a given page is displayed is an "owned" window (possesses the correct name, or correct name for window.opener) and if not, open an "owned" window and redisplay the page.

For newer Netscape browsers, their on-line manual says: "To unconditionally close a window, you need the UniversalBrowserWrite privilege." (which really means a signed script).

For more information, refer to Netscape's Javascript manual, look up the close method of the window object in the index. Microsoft browsers may not behave the same as Netscape browsers.

Recommended Resources

Discussion

Related Questions