I\'m having a problem with a \'popstate\' event handler, this is my code:
window.addEventListener(\"popstate\", function (event){
if (event.state) {
history.pushState() will not trigger the popstate event by definition.
The popstate event is fired in certain cases when navigating to a session history entry.
This event is intended to be only triggered when navigating to a history entry, either by pressing the back/forward button, or history.go/back
.
pushState
do not trigger the popstate
event, only clicking back / forward button (or use backspace) or invoking history.back()
/ history.go(n)
would trigger this event.
Also, in webkit browsers, a popstate
event would be triggered after page's onload
event, but Firefox and IE do not have this behavior.
No it will not,
As per MDN documentation
Note that just calling history.pushState() or history.replaceState() won't trigger a popstate event. The popstate event is only triggered by doing a browser action such as a click on the back button (or calling history.back() in JavaScript).
Again as per this question the popstate
event is not triggered in Chrome
when you call pushState()
.