javascript change window url without reload
HTML5: Changing the browser-URL without refreshing page
An often overlooked feature of HTML5 is the new “onpopstate” event.
This new feature offers you a way to change the URL displayed in the browser through javascript without reloading the page. It will also create a back-button event and you even have a state object you can interact with.
This means you won’t have to use the hash-hack anymore if you want add state to your AJAX-application, and search engines will be able to index your pages too.
Example :
if (history.pushState) {
window.history.pushState(“object or string”, “Title”, “/new-url”);
}
You can programmatically invoke the back-function by running:
window.history.back();
And you can of course go forward too:
window.history.forward();
Or even go to a specific history state:
window.history.go(2);
Comments
Post a Comment