Skip to content

Instantly share code, notes, and snippets.

@alxfv
Created May 8, 2014 14:09
Show Gist options
  • Save alxfv/98c4b943a25acb0aa610 to your computer and use it in GitHub Desktop.
Save alxfv/98c4b943a25acb0aa610 to your computer and use it in GitHub Desktop.
ajax history.js
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
if (State.data.state !== undefined) {
var url = State.url;
$.ajax({
url: url
}).done(function(data) {
$('.content').html(data);
});
}
});
$(document).on('click', '.b-menu > li > a', function(e) {
e.preventDefault();
var $this = $(this);
var url = $this.attr('href');
var state = $this.attr('data-state');
History.pushState({ state: state }, "State " + state, url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment