Forum Moderators: open

Message Too Old, No Replies

"javascript:history.go(-1)" in HTML

         

jk3210

3:55 pm on Nov 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's the html version of this:

javascript:history.go(-1)

I need a S/E-readable "go back" link that not only takes the user back to the previous page, but also to the exact location on the previous page --i.e. the last view they saw before coming to the current page.

Does something like this exist?

Lance

5:33 pm on Nov 16, 2004 (gmt 0)

10+ Year Member



Does something like this exist?

Not in HTML it doesn't. The only way to do something like that would be with server-side scripting writing the HTTP_REFERER into your <a> element.

Off the top of my head, it should look like this:

ASP:
<a href="<% =Request.ServerVariables("HTTP_REFERER") %>">BACK</a>

PHP:
<a href="<? echo $_SERVER['HTTP_REFERER']?>">BACK</a>

The quotes within quotes is okay here because the server-side directive will be processed before the client ever sees it.

Bernard Marx

6:05 pm on Nov 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.referrer

- Gives you the URL, if the current doc was reached via a link.

It won't place them back to the exact position on the page that they were before.

RedScourge

4:04 pm on Nov 17, 2004 (gmt 0)

10+ Year Member



if there was no referral, like you type in the address and want to go back and leave the site, this probably isnt going to work, but otherwise it would work. javascript would probably be better to use if youre worried about that case.