Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java Tip 15: How to make a "Back" button in JavaScript

How to make a "Back" button in JavaScript

  • Print
  • Feedback
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!

About the author

Subsisting on caffeine, sugar, and too little sleep, John D. Mitchell has been consulting for most of the last nine years, and developed PDA software in OO assembly language at Geoworks. He funds his Java addiction by writing compilers, Tcl/Tk, C++, and Java systems. He co-authored the hot new Java book Making Sense of Java and is currently developing a Java compiler.
  • Print
  • Feedback
What is Tech Briefcase?
TechBriefcase is a new, free service where IT Professionals can Search, Store and Share IT white papers and content like this. Learn more
Bookmark content
Speed up your research efforts with content across the web.
Search and Store
Find the white papers you need. Create folders for any topic.
View Anywhere
Open your briefcase on your iPhone, tablet or desktop. Share with colleagues.
Don't have an account yet?

Resources