views:

57

answers:

3

I have a classifieds website. In every classified, there is a back link which simply takes the browser back one step. This is because when users search classifieds, and click on one to view it, they can easily go back with a link also (instead of only the browser back button).

Here is the problem, if the classified is entered directly into the adress bar of a browser, or if somebody bookmarked a classified, then this back-link would take them someplace else...

Is there any way of making sure that the previous page is a certain page (index.php in my case)? This way I would only display the back link if the previous page was index.php...

Thanks

A: 

Why not just insert a link to index.php directly? That way you have complete control over the target of the link. No need for JavaScript.

Konrad Rudolph
because then the search results wont show up... Isn't there any way to check previous window?
Camran
Sid
@Camran: well, either use a session or GET parameters to store the query. Furthermore, the user has the “back” button **in the browser** if they really need it. No need to replicate it on the web site.
Konrad Rudolph
+2  A: 

You can't query history data. A slightly better option is to read the Referrer server variable and create your "Back" link to it. It's not very much stronger than history.go(), though. Try using a common index page instead.

Humberto
Yes, being able to read the history is blocked for security reasons.
Brock Adams
A: 

You should track their session within PHP or whatever language you're using in order to have an effective "back" button.

You could pull the data with document.referrer but that will not always give you the previous page. Sadly I am not sure of a way to achieve a "Back" button via javascript without using some kind of scripting language to track a user either via cookie or session.

Marco Ceppi