I'm developing a webpage where depending on the next or back actions I do the correspondent animation, the problem comes when using the pushstate. When I receive the event how do I know if the user clicked back or forward history buttons using the Pushstate API?, or do I have to implement something myself?
The popstate event will be triggered by doing a browser action such as a click on the back or forward button (or calling history. back() or history.
PopStateEvent is an interface for the popstate event. A popstate event is dispatched to the window every time the active history entry changes between two history entries for the same document. If the history entry being activated was created by a call to history. pushState() or was affected by a call to history.
You must implement it yourself which is quite easy.
pushState
give the data object a unique incrementing id (uid).onpopstate
handler is invoked; check the state uid against a persistent variable containing the last state uid.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