I am learning about history in HTML5, in this example (open the JavaScript browser console to see error) the event.state.url
returns:
Uncaught TypeError: Cannot read property 'url' of undefined
Look and help: http://jsfiddle.net/un4Xk/
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.
The popstate event of the Window interface is fired when the active history entry changes. ... 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. forward() in JavaScript).
html - history. pushState does not trigger 'popstate' event - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
The popstate event of the Window interface is fired when the active history entry changes while the user navigates the session history. It changes the current history entry to that of the last page the user visited or, if history.
event
is the jQuery event object, not the DOM one.
To access the DOM event object, use event.originalEvent
: http://jsfiddle.net/pimvdb/un4Xk/1/.
var state = event.originalEvent.state;
Remember that the state is only defined when the new state has data, so it is not available when clicking and then going back to the initial state:
It is, however, available when clicking, clicking another time and then going back:
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