如何在不重新加载和 # hack 的情况下更改窗口的位置? [英] How could I change window's location without reloading and # hack?

查看:32
本文介绍了如何在不重新加载和 # hack 的情况下更改窗口的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

起初我认为 hash hack 是必需的,但从 Facebook 最近的更新来看,我不这么认为.

At first I thought that hash hack is a requirement, however judging from the recent updates from facebook, I am thinking otherwise.

最初的 hash hack(我不确定这是否正确)是通过更改 location.hash,可以在不刷新页面的情况下保存 URL 中的状态.这被 Google 的应用程序、Facebook 以及最近的 #NewTwitter 广泛使用.但是今天我注意到如果您使用现代"浏览器(例如 chrome 或 firefox),Facebook 不再有这个#".我分别使用开发者工具和 firebug 仔细检查了它们是否没有重新加载.

The original hash hack (I am not sure if this is the correct term) is that by changing location.hash, one may save a state in the URL without refreshing the page. That is extensively used by Google's apps, and Facebook, and lately #NewTwitter. However today I noticed that Facebook no longer have this "#" if you use a "modern" browser - like chrome or firefox. I double checked that they are not reloading by using developer tools and firebug respectively.

通过在 stackoverflow 中进行最少的搜索,最接近解决方案的是使用 Flash - 但是我禁用了 Flash 并且 facebook.com 仍然像魅力一样工作.从 chrome 8 dev 和 firefox 4 beta 的覆盖率来看,我怀疑这可能与 HTML5 时代的 API 相关,但 Facebook 中的代码不是我的能力,我无法调试以找出它们做了什么.

With a minimal search in stackoverflow, the closest one to the solution is using Flash - however I disabled Flash and facebook.com still works like a charm. Judging from the coverage in chrome 8 dev and firefox 4 beta, I wonder that could be related to HTML5-era APIs, but the code in Facebook is not of my capacity to debug to find out what they did.

因为这是我在这里问的第一个问题,我想知道你们中是否有人已经解决了这个问题.

Since this is like the first question I ask here, I wonder if any of you may have already solved this problem.

谢谢各位.

附言不适用于 IE8,尚未在 IE9 beta 上测试.

P.S. Doesn't work on IE8, haven't tested on IE9 beta.

推荐答案

Facebook 正在使用 HTML5 中的历史 API.从这篇博文中,您可以看到这是如何工作的.基本上,他们正在调用如下所示的方法来更改 url,而无需重新加载页面.

Facebook is using the history api in HTML5. From this blog post you can see how this works. Basically they are making calls like the one below to change the url without reloading the page.

window.history.pushState("object or string", "Title", "/new-url");

这是关于它的 HTML5 工作草案规范:http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#the-location-interface

Here is the HTML5 working draft spec about it: http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#the-location-interface

遗憾的是,IE9 不支持此 api.新版本的 Chrome 和 FF 完全支持.

Sadly, IE9 does not support this api. New versions of Chrome and FF have full support.

这篇关于如何在不重新加载和 # hack 的情况下更改窗口的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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