Javascript: How do I change the URL in the address bar without refreshing the page? [closed]

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?

Answers

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");

The short answer is that all you can change in the URL without reloading the page is the hash value (the part after a #).

Changing the URL in any other way requires reloading the page. This is done for security reasons so that the content in the page always comes from the URL in the address bar and people can't be deceived otherwise.