Possible Duplicate:
How do I, with JavaScript, change the URL in the browser without loading the new page?
I noticed that web apps like GMail and GrooveShark can change the URL in the address bar of my browser without refreshing the page. Ajax is obviously used to change the content. How can I change the URL?
the page using JavaScript? Method 2: Adding a new state with pushState() Method: The pushState() method is used to add a new history entry with the properties passed as parameters. This will change the current URL to the new state given without reloading the page.
The pushState() method is used to pass the properties in the form of parameters to add the new history entry. It is used to modify the current URL with the new given state without having to reload the page.
window. location. replace() replaces the current URL with a new one, whilst overwriting the old URL's entry in the history.
HTML5 History API allows browsers to change the URL in browser address bar without reloading or refreshing the page using pushState function. The pushState method works similar to window.
Gmail and Grooveshark only change the hash, this is done by changing:
location.hash = 'blah'
If you target HTML5 enabled browsers, you can use window.history.pushState and window.history.popState, see http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page
You may want to look into HTML5 push state. I know iQuery Mobile is using this feature to modify the location URL without triggering a page load and it might be the right solution for you.
https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history
Here is an example of how it works:
window.history.pushState(data, "Title", "/new-url");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With