Skip to content

Instantly share code, notes, and snippets.

@luisnomad
Created September 17, 2013 14:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisnomad/6595170 to your computer and use it in GitHub Desktop.
Save luisnomad/6595170 to your computer and use it in GitHub Desktop.
Modify the URL without reloading the page
// This can now be done in Chrome, Safari, FF4+, and IE10pp4+!
// Updating address bar with new URL without hash or reloading the page
// Example:
function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
}
// You can then use window.onpopstate to detect the back/forward button navigation:
window.onpopstate = function(e){
if(e.state){
document.getElementById("content").innerHTML = e.state.html;
document.title = e.state.pageTitle;
}
};
/*
More here:
http://spoiledmilk.com/blog/html5-changing-the-browser-url-without-refreshing-page/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment