I\'m playing with window.onpopstate
, and there is a thing that annoys me a little bit:
Browsers tend to handle the popstate event differe
To react on popstate
event, you need to push some state onto the session history.
For example add this line to the document ready section:
history.pushState(null, null, window.location.pathname);
Not ideal, but it works in Chrome, Firefox and other browsers as well.
Then the event is fired correctly when user clicks on Back or Forward button, also when history.back()
, history.forward()
, history.go()
methods are called manually. Each time when popstate
has been invoked, you have to push another state again to make it working.
See also: