JavaScript的:如何更改在地址栏中的URL而无需刷新页面? [英] Javascript: How do I change the URL in the address bar without refreshing the page?

查看:143
本文介绍了JavaScript的:如何更改在地址栏中的URL而无需刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/136458/how-do-i-with-javascript-change-the-url-in-the-browser-without-loading-the-new">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,请参阅<一href="http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page">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

这篇关于JavaScript的:如何更改在地址栏中的URL而无需刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆