Simulating the BACK button

  Michendi 23:57 17 Nov 2004

The browser BACK button can be simulated in a document in everyone of the latest browsers - except IE6 - with the behaviour script onclick="window.back()" or the JavaScript a href="javascript:history.back()">. Assume a button "Close Window". If either of the above scripts are associated with this button then when a visitor clicks the button they will go back to the page they came from.... except in IE6. In IE6 the behaviour script generates an "Error on page" and the JavaScript does nothing. Does any web developer know the correct syntax to get either of these scripts to work in IE6?

  Gaz 25 01:28 18 Nov 2004

"To Gaz 25. I agree that should work, but once again it doesn't in IE6. I have removed the "onclick=window.back()" script and replaced it with your script. Works fine in all the other browsers.... but $£*&^" not in IE6. Oh Bill we just love you :-( "

That's very odd, it works fine here on my website. Have you Active Scripting disabled in IE?

Otherwise, let us have a link to your website and test the code for you. This will help diagnose if the problem is with the webpage or IE on your computer.

  Taran 01:35 18 Nov 2004

Back and forward history buttons, for pages visited (sorry to state the obvious)

<input type="button" value="back" onClick="opener.history.go(-1)">
<input type="button" value="forward" onClick="opener.history.go(1)">

Back button on its own:


Using an image of your own choosing as the button:




<IMG SRC="images/back.gif"


This assumes that your Back button image is called back.gif and is located in the images folder in your web root folder.

A standard text hyperlink back link:




[Go Back]</A>

Note that I've included some hard returns in the code snippets to prevent the forum from turning the links from turning into one of the blue 'click here' links.

Dynamic pages sometimes need a few extra tweaks to get a reasonably effective JavaScript 'back' button but using a cookie or (even better) a user session with cookies can allow you to offer a working solution. However, I'm not getting into that topic unless you request it and unless you specify the language you want to work with, since user sessions and cookies are no small subject for discussion.

Hope the above points you in the right direction.


  Michendi 18:15 20 Nov 2004

Reply to TARAN...
Thanks for the info. I eventually settled on the "onclick=history.go(-1)" solution which works in all browsers tested. I had not used this specific syntax before so I have learnt something :-) Thanks.

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

iMac Pro review

See iconic duo Smith and Foulkes' epic animation for the BBC's Winter Olympics coverage

iMac Pro review

Idées cadeaux pour geeks et tech addicts