Given a webapp with ajax navigation, you intend to make use of html5's history navigation.
But: binding onto the popstate event it is not triggered. Excep on page load, when it is:
If HTML5 available (it is detected correctly, demos do work as well in Chrome as FF):
// Callback
function historyChangeHandler(data) {
console.log(data);
}
// Bind
$(window).bind('popstate', historyChangeHandler);
// Trigger
$("a").click(function(e) {
var url = "/";
// ...
console.log("clicked");
history.pushState({url: url}, "", url);
return false;
});
What does not work:
What I tried:
What does work:
Any clues I miss?
Why do you need the popstate event to fire? Why not just call your function?
$("a").click(function(e) {
var url = "/";
// ...
console.log("clicked");
history.pushState({url: url}, "", url);
historyChangeHandler({url: url});
return false;
});