Forum Moderators: open

Message Too Old, No Replies

"Back" button to take you to product listing

...but do not go back if this takes you outside the site.... How to do it?

         

aakk9999

1:21 am on Dec 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have a number of product listing pages and also product details page for each of the product listed.

Product Details page is an ordinary static html page whilst product listing is a dynamically created page.

Product Details page has a link "Back to listing".

If the user arrived to product detail page from one of the listing pages, then I want to go back to appropriate listing page (can use js history.back here)

However, if the user has arrived to Product Details page directly (from search engine, from Bookmarks or by typing in URL), then I want "Back to listing" to take the user to the first page of product listing.

How do I achieve this in static html page? I presume javascript and cookie? Does anyone know the piece of code as I am not js expert.

eelixduppy

11:05 pm on Dec 29, 2008 (gmt 0)



You can check the value of
history.previous
possibly using a regular expression to see if it came from your site through linking. If it did, then you'd go back in history with
history.back()
otherwise you can change the location:
document.location = '/path/to/page'
. Note that none of this will work if javascript is disabled.

Take a look and see what you can do. :)