JavaScript的:如何更改在地址栏中的URL而无需刷新页面?

问题描述:

可能重复:
  How我,用JavaScript,但不加载新的页面更改浏览器的网址是什么?

我注意到,像Gmail和歌词的网络应用程序可以改变我的浏览器的地址栏中的URL而无需刷新页面。 Ajax的显然是用于改变内容。我如何更改URL?

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?

Gmail和歌词只改变了哈希,这是通过改变完成的:

Gmail and Grooveshark only change the hash, this is done by changing:

location.hash = 'blah'

如果你的目标HTML5功能的浏览器,你可以使用window.history.pushState和window.history.popState,请参阅http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page

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