I am refreshing some pages with AJAX and so an updating the history with the following code -
/** Update the page history */
var pushState_object = {
aja
The initial state does not have a .state
property available, because you didn't use .pushState
to add such data (it was loaded the normal way as you describe).
What you do know though, is that if there is no .state
, it must be the original state, so you can use an else
block like this: http://jsfiddle.net/pimvdb/CCgDn/1/.
Lastly, you can use e.state
.
window.onpopstate = function(e){
if(e.state !== null) { // state data available
// load the page using state data
initiate_load_updated_page(e.state.ajax_string, window.history.state.security, 0);
} else { // no state data available
// load initial page which was there at first page load
}
}