0

In javascript history api, I can do something like this

window.addEventListener('popstate', event => {
    var data = event.state;

}, false);

but is there a way I can tell if the user clicked the back or forward button? Note: this is not about if they clicked one of the two, but its to distinguish which of the 2 they clicked on.

Thanks

omega
  • 40,311
  • 81
  • 251
  • 474
  • Make a comparison between previous history entry and target location of the popstate event – Simon Hyll Mar 05 '18 at 02:04
  • Can you show code? – omega Mar 07 '18 at 20:02
  • Maybe later. All you need though is something along the lines of `history.next == history.previous ? Back pressed : Forward pressed` – Simon Hyll Mar 13 '18 at 17:12
  • @Simon Those properties aren’t likely to be accessible in most browsers. Anyway, I posted some code in answer to the [other question](https://stackoverflow.com/questions/8980255), in case it helps. – Michael Allan Mar 16 '18 at 21:43

0 Answers0