无需重新加载页面更新浏览器的网址 [英] Update browser's URL without reloading the page

查看:222
本文介绍了无需重新加载页面更新浏览器的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能改变在浏览器的地址栏中显示的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')

请参阅<一href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState%28%29.c2.a0method">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).

这篇关于无需重新加载页面更新浏览器的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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