0

I'm struggling finding a way to detect if user used BACK button to get to my website either with JavaScript or jQuery.

How can I detect that activity?

Trow Way
  • 45
  • 3
saulenzo7
  • 51
  • 12
  • 2
    Possible duplicate of [Track when user hits back button on the browser](http://stackoverflow.com/questions/55871/track-when-user-hits-back-button-on-the-browser) – Nathan Tuggy Nov 08 '15 at 02:16

1 Answers1

0

HTML5 History data. "A popstate event is dispatched to the window every time the active history entry changes." Then do a JavaScript check on their past history to see if it matches one of your pages, or to see if this is the first page they've visited used, check history.length = 1. https://developer.mozilla.org/en-US/docs/Web/API/History_API

Store a cookie that shows they were on that page previously. If you're needing to tell if it is not the users first time visiting a page.

Have hidden form data that posts, but the user may be asked to resubmit it when going back to the page (wouldn't recommend).

I don't believe there is a way to access a users browser history outside of your website's scope for security reasons.

TheWandererLee
  • 1,012
  • 5
  • 14
  • Thank you for answer, but I would like to note, that it doesn't work for me on Mobile, as mobile doesn't refresh the website when you go back – saulenzo7 Nov 08 '15 at 03:00
  • Does checking the event.persisted value of window.onpageshow(event) function work for you or another method from [this answer](http://stackoverflow.com/questions/11979156/mobile-safari-back-button)? – TheWandererLee Nov 08 '15 at 03:09
  • Yea, I tried these solutions, it doesn't do anything when I click back button on android. – saulenzo7 Nov 08 '15 at 04:25