skip to Main Content

I have a page which displays a filter-style menu that users can click to display particular listing category. When they click a listing thumbnail it opens the full listing page. At the top of that page is a "Back" text link. I need that link to return to the exact filtered category of the previous page.

The filtered category URL is something like this:

/residential/#listing-category

On the "Back" text link of the full listing page, I’ve tried:

<a href="javascript:history.back()">Back</a>

and also tried:

<a href="javascript:history.go(-1)">Back</a>

However, those only return to
/residential instead of /residential/#listing-category

How do I get the Back link to return to the full URL (e.g. /residential/#listing-category)?

2

Answers


  1. Here is one of the methods:

    Assume the previous page is Page A (URL is: /residential/#listing-category) while the destination page is Page B (URL is /destination/)

    1. On Page A, when you click on a link to Page B, record the hash part using either var hash = window.location.hash.substring(1); or var hash = $(location).attr('hash'); (if you have jQuery)

    2. Save the hash variable in the cookie.

    3. Navigate to the Page B.

    4. In Page B, set the "back link" with the Page A URL combined with the cookie hash value.

    Alternatively, you can save the whole URL of Page A in a cookie before you navigate, then set the "back link" with the Page A URL stored in the cookie just now on Page B. The first method is more flexible, though.

    Login or Signup to reply.
  2. Store the URL in session storage

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search