Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q452 Is there a way to close a window without that confirm message?

You are here: irt.org | FAQ | JavaScript | Window | Q452 [ previous next ]

The only way to avoid the message appearing is when you close a window that only has one location in its history. Most visitors to a site will have many locations in their current history.

If you are creating a window that you then want to close later on without the message occurring, then make sure that you use the JavaScript replace() method when changing the location within that window, that way you will not create new entries within that windows history object.

To use the replace method without causing errors on browsers that don't support it you'll need to do the following:

<script language="JavaScript"><!--
function go(url) {
    if (document.images)
        location.replace(url);
    else
        location.href = url;
}
//--></script>

And then for all your links in that window:

<a href="javascript:go('http://somewhere.com/nextpage.html')">Next Page</a>

Make sure you use the absolute URL, because in some versions of Opera, an absolute reference will cause problems when used with the replace() method.

Note that for browsers that don't support the replace method (the same as those that don't support the image object) the window will build up entries in the history object.

Yves Debilloëz writes:

If you sign your javascript, and the user has trusted the signer, it is possible to close the window without notification.

Feedback on 'Q452 Is there a way to close a window without that confirm message?'

©2018 Martin Webb