Created
March 14, 2014 13:42
-
-
Save cethap/9547862 to your computer and use it in GitHub Desktop.
ShortJsGist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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