简体   繁体   English

如何在不重新加载和#hack的情况下更改窗口的位置?

[英]How could I change window's location without reloading and # hack?

At first I thought that hash hack is a requirement, however judging from the recent updates from facebook, I am thinking otherwise. 起初我认为哈希黑客是一个要求,但从Facebook最近的更新来看,我正在考虑其他方面。

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. 原始哈希黑客(我不确定这是否是正确的术语)是通过更改location.hash,可以在URL中保存状态而不刷新页面。 That is extensively used by Google's apps, and Facebook, and lately #NewTwitter. 谷歌的应用程序和Facebook以及最近的#NewTwitter广泛使用它。 However today I noticed that Facebook no longer have this "#" if you use a "modern" browser - like chrome or firefox. 然而今天我注意到,如果你使用“现代”浏览器(如chrome或firefox),Facebook将不再拥有这个“#”。 I double checked that they are not reloading by using developer tools and firebug respectively. 我分别使用开发人员工具和firebug检查了他们没有重新加载。

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. 使用stackoverflow中的最小搜索,最接近解决方案的是使用Flash - 但是我禁用了Flash,而facebook.com仍然像魅力一样。 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. 从chrome 8 dev和firefox 4 beta的覆盖范围来看,我想知道这可能与HTML5时代的API有关,但Facebook中的代码不是我调试的能力,以找出他们做了什么。

Since this is like the first question I ask here, I wonder if any of you may have already solved this problem. 因为这就像我在这里提出的第一个问题,我想知道你们中是否有人已经解决了这个问题。

Thanks guys. 多谢你们。

PS Doesn't work on IE8, haven't tested on IE9 beta. PS无法在IE8上运行,尚未在IE9测试版上测试过。

Facebook is using the history api in HTML5. Facebook正在使用HTML5中的历史API。 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. 基本上他们正在调用下面的调用来更改URL而不重新加载页面。

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

Here is the HTML5 working draft spec about it: http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#the-location-interface 以下是关于它的HTML5工作草案规范: http//www.whatwg.org/specs/web-apps/current-work/multipage/history.html#the-location-interface

Sadly, IE9 does not support this api. 遗憾的是,IE9不支持这种api。 New versions of Chrome and FF have full support. 新版Chrome和FF完全支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM