Workshop: Creating Back and Forward Buttons
One common use for the back and forward methods of the history object is to add your own Back and Forward buttons to a Web document. This can improve the user interface of your pages.
As an example of the use of the history object, you will now create a script that displays Back and Forward buttons and uses these methods to navigate the browser.
You will use graphic images for the Back and Forward buttons. You can use the images from this book's Web site or make your own images to match the other graphics on your page.
Visit this book's Web site to download the listings for this hour and the graphics for the Back and Forward buttons: http://www.jsworkshop.com/.
Here's the part of the script that will handle the Back button:
With these out of the way, you just need to build the rest of an HTML document. Listing 9.2 shows the complete HTML document, and Figure 9.2 shows a browser's display of the document. After you load this document into a browser, visit other URLs and make sure the Back and Forward buttons work.
Figure 9.2. The Back and Forward buttons in Internet Explorer.