Skip to content

Instantly share code, notes, and snippets.

@cethap
Created March 14, 2014 13:42
Show Gist options
  • Save cethap/9547862 to your computer and use it in GitHub Desktop.
Save cethap/9547862 to your computer and use it in GitHub Desktop.
ShortJsGist
/*This can now be done in Chrome, Safari, FF4+, and IE10pp4+!
See this question's answer for more info: 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;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment