I am grabbing popstate and need to do various thing based on the current and originalEvent in the history stack. However, I can't figure out how to get the current state for comparison, but originalEvent works. Here's my JS code. The first IF statement throws an exception that e.state.id is not defined...
$(window).on("popstate", function(e) {
//check and compare current state
if (e.state.id == 'something') { // throws an exception
*do something*
} else if (e.originalEvent.state !== null) { //previous state exists?
*do something*
} else { //no previous state
*do something*
}
});
FYI, the push state is being set as:
history.pushState({id: 'view'}, '', '/view');
Extended History Object
This is my source you can see full resource from https://gist.github.com/HasanDelibas/12050fc59d675181ea973d21f882081a
This library contains:
state
must be object athistory.pushState( **state**, ...)
Now you can get all states with
history.states
object, and detect history change withaddEventListener("popstate",function(e))
Using