Skip to content

Instantly share code, notes, and snippets.

@d33pfri3d
Created June 8, 2012 13:14
Show Gist options
  • Save d33pfri3d/2895545 to your computer and use it in GitHub Desktop.
Save d33pfri3d/2895545 to your computer and use it in GitHub Desktop.
JQUERY: History API
$('a[href^="/"]').click(function(e){
var target = e.currentTarget;
if (!e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey){
e.preventDefault();
url = target.pathname;
navigate(url, {triggered: true});
}
});
function navigate(url, data){
history.pushState(data, '', url);
}
window.onpopstate = function (event){
if (event.state.triggered){
ajaxLoad(location.pathname);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment