Idocs Guide to HTML

Back Link: The Basics

The first step in implementing the back link is to download backlink.js and upload it to your server. Load backlink.js into your web page with a <SCRIPT SRC="..."> tag like this:

<SCRIPT TYPE="text/javascript" SRC="backlink.js"></SCRIPT>

backlink.js is implemented by putting a short script in your page. that creates a backlink object, sets various optional properties of the object (we’ll go over all of them later in this section), then calls the write() method of the object. For example, the following script uses a the backlink code in its simplest form, creating a backlink object, then immediately writing it out:

<SCRIPT TYPE="text/javascript">
var bl = new backlink();

which gives us this back link:

Let's take a look at this basic example. Line 1 opens the script element and line 2 sets the obligatory comment for older browsers. Line 3 creates a backlink object, storing it in the bl variable. Line 4 then calls the backlink object’s write() method which writes out the HTML code for the link. 5 closes the comment and 6 closes the script element.

No History, No Link

The backlink object uses object detection to test if the history.back() method works. If the browser does not support history.back(), or if the browser is in the first page it has loaded since the browser opened (i.e. there is no page to go "back" to), then the back link is not written out. This is why it is better to use a scripting object to write out the link instead of hardcoding the link into the page.

Now let's look at customizing the back link.

Copyright 1997-2002 Idocs Inc. Content in this guide is offered freely to the public under the terms of the Open Content License and the Open Publication License. Contents may be redistributed or republished freely under these terms so long as credit to the original creator and contributors is maintained.