One of the most common features that many web designers like to add to their web pages is a "go to previous" button or link, also known as an HTML back button, that sends the user to the last web page they visited.
How the HTML Back Button Helps Navigation
One of the most important aspects of any web page is creating seamless and intuitive navigation for your visitors. When you have "internal" pages that are linked from several other pages, it can be somewhat difficult to guess where the visitor came from. In the case where visitors arrived at the page from a search engine or other link, it's impossible to know. However, by using an HTML back button, you can provide your visitors with the convenience of a link that returns them to the page where they came from. While users do normally have the option to use the browser "back" button, which would do the same thing, providing a link on your page adds convenience and intuitiveness to your website.
Programming a Back Button with HTML
<a href="yourpage.html" onclick="window.back()">Return to Previous Page</a>
<a href="yourpage.html" onclick="history.go(-1);">Return to Previous Page</a>
<FORM><INPUT TYPE="button" VALUE="Previous Page" onClick="history.go(-1);"> </FORM>
Using Server Side Scripts
Sample script using CGI:
<A HREF="<!--#echo var="HTTP_REFERER"-->">Go to Previous Page</A>
The HTTP_REFERER variable is the URL that referred the visitor to the current web page. If your scripting language of choice is PHP, then to access the referer variable and link to the previous page, you would create a text link using the following code.
<?php echo '<a href="' . $_SERVER["REFERER"] . '">Go to Previous Page</a>'; ?>
Or a form button using this code:
<?php echo '<form action="' . $_SERVER["REFERER"] . '" method="get"> <input type="submit" value="Previous Page"> </form>'; ?>
Adding the feature to "go back" to previous pages seems like a very simple concept, but when you're trying to incorporate the simplest and most intuitive navigation into your website, these methods of adding such a feature become an indispensable part of any web programmer's toolbox.