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

Q244 How do I tell the browser not to save the current URL in the history folder?

You are here: irt.org | FAQ | JavaScript | History | Q244 [ previous next ]

You cannot tell the browser to not store the URL in the history. What you can do though, for those browsers that support this, is to overwrite the current URL in the history when moving onto another page.

Normal links look like:

<A HREF="apage.html">Go to a page</A>

This can be done using JavaScript:

<SCRIPT LANGUAGE="JavaScript"><!--
function go(url) {
    location.href = url;
}
//--></SCRIPT>

<A HREF="javascript:go('apage.html')">Got to a page</A>

This can be enhanced to replace the current URL in the history:

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

<A HREF="javascript:go('http://www.somewhere.com/apage.html')">Got to a page</A>

The check for the image object is the easiest way to detect if the browser supports the location objects replace()method.

Note: in Opera replace() will work, but only with absolute URL's.

Feedback on 'Q244 How do I tell the browser not to save the current URL in the history folder?'

©2018 Martin Webb