更新浏览器地址栏而不重新加载 [英] Update browser address bar without reload
问题描述
我喜欢facebook在图像之间滚动时更改浏览器地址栏的URL的方式,以及它在IE7上的工作方式。但是,我只是在HTML5浏览器上找到了有关如何操作的信息,我想支持IE7。
I like the way facebook changes the URL of the browser address bar when you scroll between images, and how it works on IE7. However, I've only found information on how to do it on HTML5 browsers, and I want to support IE7.
由于这是一个HTML5解决方案,因此:
As this is a HTML5 solution, the following:
window.history.pushState("object or string", "Title", "/new-url");
如果有其他可用解决方案,则不是一个选项。
is not an option if there's another solution available.
编辑
在任何哈希值之前。
但是有吗?
推荐答案
我唯一的另一个选择m知道涉及使用 #hash
片段来确定使用 hashchange
事件,IE7不支持:
The only other option I'm aware of involves using the #hash
fragment to determine the "url" or "state" of the page using the hashchange
event, which is not supported in IE7:
http://caniuse.com/#search=hashchange
但是,有polyfill:
However, there are polyfills:
http://benalman.com/projects/jquery-hashchange-plugin/
这是一个相当hacky的方法,它打破了HTTP协议,因为依赖在javascript上输出正确的内容,但你可能不关心那:
It's a rather hacky approach and it breaks HTTP protocol since it relies on javascript to output the correct content, but you may not care about that:
http:// isolani .co.uk /博客/ JavaScript的/ BreakingTheWebWithHashBangs
History.js
声称跨浏览器支持,虽然我没有使用它(使用HTML5浏览器的历史记录,旧版本的哈希更改):
History.js
claims cross-browser support, although I haven't used it (uses history for HTML5 browsers, hashchange for older ones):
https://github.com/browserstate/History.js/
这篇关于更新浏览器地址栏而不重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!