balupton/history.js — Issue #123: URL and title updated, but back button does not refresh page
Author: RWAP
Created: 2011-11-09 13:04:21+00:00
State: open

Maybe I have misunderstood the workings of history.js, but I am using it on a site where various sections of the page are loaded using jQuery Ajax.

As each section is loaded, they call a main function:
AjaxPageLoaded ()

This has been amended to include the code:
(function(window,undefined){
// Prepare
var History = window.History; // Note: We are using a capital H instead of a lower h
if ( !History.enabled ) {
// History.js is disabled for this browser.
// This is because we can optionally choose to support HTML4 browsers or not.
return false;
}

// Bind to StateChange Event
History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
var State = History.getState(); // Note: We are using History.getState() instead of event.state
History.log(State.data, State.title, State.url);
});

// Store current Ajax page in browser history
History.pushState({state:1}, ' - '+visibleTag, 'user/profile/_'+visibleTab+'/_'+visibleTag);
})(window);

I see the URL bar and the title in the browser are updated to the correct values when each Ajax section is loaded.

However, pressing the back button shows the previous URL and title (as it should), but does not reload the page to display the old Ajax section.

What am I missing?