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)?
When using hash links browser does not store the hash part in the history, but you can manually add a new history to the current session whenever moving to a hash link on the page using history.pushState.
history.pushState(state, '', window.location.href) // state can be null or {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With