How to make a "Back" button in JavaScript
Do you have a hankering for a button that you can put anywhere you please in your HTML document — and that allows users to go back to the document they were previously viewing? Perhaps this is a sign of my laziness, but I think about it regularly. I hate to have to move the mouse cursor all the way up to the browser’s “Back” button when scrolling through long pages.
Well, I don’t have a Java solution for you but Robert Raught sent in this cute little JavaScript code that provides the functionality of the browser’s “Back” button:
<a href="javascript:history.go(-1)" onMouseOver="self.status=document.referrer;return true">Go Back</a>
Check out this example of the BackButton script in action.
Some things to note:
- It only works with browsers supporting JavaScript (i.e., Netscape Navigator).
- It shows the target URL in the status bar but:
- For some bizarre reason it does so only when the page was referred to via a hotlink.
- It does not show the target URL if you type the URL directly or if you use Java’s showDocument() method to display a page.
Enjoy!


