balupton/history.js — Issue #138: window.onstatechange won't fire
Author: dansurfrider
Created: 2011-12-16 14:36:38+00:00
State: open

I'm not really sure whether this is a bug or if I'm just understanding/doing something wrong.

But isn't the `window.onstatechange` supposed to fire when you hit the back/forward button of your browser when you previously changed the state with `History.stateObj` ?

I actually see the object changing in the Firebug console, but `window.onstatechange` just won't fire! Also - very confusing - when I use `window.onpopstate` instead, the object isn't changing anymore (when using the back/forward button).

Here's what I do:

$('.container').click(function(e) {
e.preventDefault();
var title = $(this).data('title');
stateObj = { show: title }
History.pushState(stateObj, document.title, '?show=' + title);
}

window.onstatechange = function() {
var title = History.getState().data['show'];
alert('title');
}

I already found that I have to use:

History.Adapter.bind(window,'statechange',function(){
var title = History.getState().data['show'];
alert('title');

});

...which works, but I still don't really understand why `window.onstatechange` won't fire?!

Any suggestions ?