How to Create a Back Button That Works

< Webhelp

Using Server Side Includes

Alright, I'm tired of seeing all the JavaScript back buttons that sometimes work. If your server is capable (requires XSSI) it will work all the time regardless of the browser. An alternative could be cobbled together with CGI if your server doesn't support Extended SSI. (Or hollar at your host till they upgrade.)

Essentially you need to examine the HTTP_REFERER before creating a link with it.

<!--#if expr="${HTTP_REFERER} =/http/" -->
<A HREF="<!--#echo var="HTTP_REFERER" -->">Back</A>
<!--#else -->
[No HTTP_REFERER is present]
<!--#endif -->

You would probably want to leave that third and fourth line out in practice. And 'Back' could of course be replaced with an image or whatever.

Here is a working example (or as working as it can be): [No HTTP_REFERER is present]


This method of creating a Back Button with SSI creates a forward link, i.e. it is not the same as hitting the browser's Back Button and risks causing confusion. Not sure what I'm talking about? I'll try to explain:

A Java Script method would go backward in the browser's history and thus keep things more orderly but alas, you need to have Java Script enabled/available on the user's browser. If you decide to use the Java Script method, it is best to do so as a document.write() so the link text only appears when the link will actually work; otherwise a broken link appears and makes you look bad.

©2000-2001 Feedback