Click to See Complete Forum and Search --> : how to make link same as back button?


Technetium
07-16-2003, 03:12 PM
I have a page that can be accessed from many other pages. There is a single link on that page that says "Back". I know it is possible through javascript to make that link function the same as pressing the browser's back button, but I can't remember how. I'm aiming for Mozilla compliancy, so it can't be something that involves IE-only language.

Khalid Ali
07-16-2003, 03:39 PM
<a href="javascript:void(0);" onclick="history.go(-1)">Back</a>

Charles
07-16-2003, 04:41 PM
The example above is perfectly valid as is but you will end up with a dead link for the 13% fo users that do not use JavaScript. Consider drawing the link with JavaScript to avoid the embarrassment.

<script type="text/javascript">
<!--
document.write('<a href="#">Back</a>');
document.links[document.links.length-1].onclick = function () {history.back(); return false}
// -->
</script>