PDA

View Full Version : Sending visitor back 2 pages on 'history'


^KoalaBear^
11-14-2002, 12:11 AM
Hi everyone!
Can somebody please help me with the js code that will send a visitor back a certain number of pages.. in this case 2.. on the click of an image.gif?
Cheers
KB...
:thumbsup:

glenngv
11-14-2002, 01:56 AM
<a href="javascript:history.go(-2)"><img src="back.gif"></a>

JustAsking
11-14-2002, 02:11 AM
Koala,

Do you mean something as simple as this:

<p><a href="javascript:history.back(2);"><img src="image.gif" border="0" alt="" /></a></p>

or have I misunderstood.

^KoalaBear^
11-14-2002, 02:43 AM
Many thanks fellas... I think either might do the trick. My site is down at the moment so I'll try them as soon as we're back up!
KB...

:thumbsup:

glenngv
11-14-2002, 02:52 AM
Originally posted by JustAsking
Koala,

Do you mean something as simple as this:

<p><a href="javascript:history.back(2);"><img src="image.gif" border="0" alt="" /></a></p>

or have I misunderstood.

history.back() method has no parameter. It just go to the previous page which is equivalent to history.go(-1)

even if you specify history.back(2), it will still go 1 page back.

so the only solution is to use history.go(-2)

^KoalaBear^
11-14-2002, 02:56 AM
Thanks for the further advice, Mate... I'm sure JA will appreciate it too!
:thumbsup:

JustAsking
11-14-2002, 03:05 AM
erhhh..

I use history.back(2) and it DOES go back 2nd last previous page visited. Why would it do that if what you explained is correct?

glenngv
11-14-2002, 04:00 AM
i read the javascript reference from devguru (http://www.devguru.com/Technologies/ecmascript/quickref/history.html) to verify the syntax of history.back() and it doesn't mention of any parameter in this method.
And I tested history.back(2) before i posted just to make sure, and it only went one page back! Im using IE 5.5.