我怎么可以改变窗口的位置,无需重新加载和#黑客? [英] How could I change window's location without reloading and # hack?

查看:161
本文介绍了我怎么可以改变窗口的位置,无需重新加载和#黑客?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

起初我以为哈希黑客是一个要求,从Facebook上的最新更新不过来判断,我想并非如此。

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

原哈希破解(我不知道这是否是正确的术语)是通过改变的location.hash,可以保存URL中的状态,而无需刷新页面。这是广泛使用谷歌的应用程序,和Facebook,最近#NewTwitter。然而今天,我发现Facebook的不再有这样的#,如果你使用现代浏览器 - 类似Chrome或Firefox。我双重检查,他们没有重装使用开发工具和萤火虫分别。

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.

随着计算器最小搜索,最近的一个解决方案是使用Flash - 但是我禁用Flash和facebook.com仍然工作就像一个魅力。 从镀铬8开发和Firefox 4测试版的报道来看,我想这可能与HTML5时代的API,但code在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.

谢谢你们。

P.S。不IE8的工作,并没有对IE9测试版的测试。

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工作规范草案:<一href="http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#the-location-interface">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.

这篇关于我怎么可以改变窗口的位置,无需重新加载和#黑客?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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