JavaScript: Link History


Introduction

Author: Martin Warning
Year: 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: The following code is an example link:
<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.



Pinternet.net: The world of beer on the Internet
Printed from: http://flyinglowlander.com/ (5/20/2012)
© FlyingLowander.com 2006 - 2012

Visit http://flyinglowlander.com for more XHTML, CSS, ASP and JavaScript examples, templates and tutorials.