How to determine the prior page (i.e. page the back button will go to)

R

Rich

Am just beginning to use javascript.

I have some pages that can be arrived at from more than one other
page. Yes, the user can use the back button but I'd like to have a
back link at the bottom of the page.

Thought there would be a url in referrer but it seem to be empty.
 
M

Maarten

Sorry, acts at once in html. Simply replace ... with < before and with >
after line.

....a href="javascript:history.back();">Back to index</a...
 
C

C.Panteliadis

Rich said:
Am just beginning to use javascript.

I have some pages that can be arrived at from more than one other
page. Yes, the user can use the back button but I'd like to have a
back link at the bottom of the page.

Thought there would be a url in referrer but it seem to be empty.

If you get an answer send me a notification. I have the same problem.
 
M

Michael Winter

<a href="javascript:history.back();">Previous Page</a>

Don't use the JavaScript pseudo-protocol when you don't need to. Consider
what will happen when JavaScript is disabled.

To the OP:

Creating your own "Back" link that doesn't go to a fixed location can be a
bad idea. For a couple of reasons:

- If the user has JavaScript disabled, your link will do absolutely
nothing and frustrate the user.
- If the user goes directly to the page (from their history, or a
bookmark), going "back" is meaningless and it makes your site unnavigable.
I come across this frequently, and it's very annoying.

If the user wants to go back through their history, let them use the
appropriate button. However, if you insist on creating your own link, use:

<a href="anActualPage.html" onclick="window.history.back(); return
false">Back</a>

You'll have to choose a sensible location for "anActualPage.html", which
should be a common root for all of the possible referring pages (like the
main site page). Note that this solution will still leave the second
problem above unresolved. Only a fixed address, with no JavaScript
interrupting the link, can solve it.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top