JavaScript: Link History
Introduction
Author: Martin WarningYear: 2007
License: Free
Sometimes you want that if a user clicks a link that this isn't registered in the browser back history list. This can be useful when using frames where you just want content pages registered, but don't want to register menu page changes.
The key to this is the JavaScript code location.replace. Whenever using this to open a page, the page won't be registered in the browser back history.
Code
Languages:- JavaScript
- XHTML
<a href="" onclick="location.replace('page.html'); return false;">Page</a>
This will replace the location with page.html. return false is used to prevent triggering the href attribute of the link.
The following example will add a value to the href attribute:
<a href="page.html" onclick="location.replace('page.html'); return false;">Page</a>
It is a good idea to also have the page to be opened in the href attribute. This way users with JavaScript disabled can still use the link. Of course in that case the link will be registered in the browser back history, but users with JavaScript enabled will still not have it registered in the browser back history. The return false; statement prevents the href to be executed when JavaScript is enabled.
