I\'m using the new HTML5 onpopstate event. Using Firefox 4 the window.onpopstate event is triggered on a page load whilst in Webkit this does not seem to be the case.
<
In case someone is interested, I've came up with a decent pattern for working with onpopstate (this code assumes jQuery, feature detection checks are stripped for clarity):
$(function() {
// 1. Add initial state to current history record on page load.
var href = location.href;
history.replaceState({"href": href}, null, href);
// 2. Now attach the popstate handler.
window.onpopstate = function(ev) {
// Raised on page load this event will still contain no state.
var state = ev.state;
if (state && state.href) {
// 3. Add your logic, use `state` and `state.href` as you see fit.
}
};
});