Created
September 17, 2013 14:34
-
-
Save luisnomad/6595170 to your computer and use it in GitHub Desktop.
Modify the URL without reloading the page
This file contains hidden or 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+! | |
// 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