无需重新加载页面更新浏览器的网址加载、浏览器、页面、网址

由网友(像个笑话)分享简介:是否有可能改变在浏览器的地址栏中显示的URL,而无需浏览器进入该页面?比如,例如,通过Ajax调用更新页面内容后?Is it possible to change the URL shown in the browser's address bar without having the browser go to t...

是否有可能改变在浏览器的地址栏中显示的URL,而无需浏览器进入该页面?比如,例如,通过Ajax调用更新页面内容后?

Is it possible to change the URL shown in the browser's address bar without having the browser go to that page? Such as, for example, after updating a page's content via an AJAX call?

我的理解是,这是不可能的,这就是为什么网站,如Twitter和Facebook更新AJAX调用的哈希标签。

My understanding is that this is not possible, which is why sites such as twitter and facebook update the hash-tag on ajax calls.

这是直到今天,当我去 http://8tracks.com/ 并开始在右手与过滤玩方...打开和关闭不同的流派,我注意到,即使是做Ajax调用刷新页面上的内容,该URL也正在动态更新。

That is until today, when I went on http://8tracks.com/ and started to play with the filter on the right hand side... turning different genres on and off, I noticed that even though it was doing ajax calls to refresh the content on the page, the URL was also being dynamically updated.

有谁知道他们是如何做到这一点?

Does anyone know how they do this?

(顺便说一句,我目前使用Chrome浏览器,但是当我回去和IE9又看了一遍,我注意到,该URL不会更新..这是可能是Chrome浏览器嘛?)

(aside, I'm currently using Chrome, but when I went back and looked again with IE9, I noticed that the URL was not being updated.. is this maybe a Chrome only thing?)

推荐答案

这是可能的在现代浏览器使用HTML5历史API:

This is possible in modern browsers by using the HTML5 History API:

history.pushState(null, null, '/some-path')

请参阅https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState%28%29.c2.a0method

这在Firefox,Chrome浏览器,歌剧,Safari浏览器(不是IE)。

This works in Firefox, Chrome, Opera, Safari (not IE).

阅读全文

相关推荐

最新文章