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

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

问题描述

起初我以为哈希黑客是一个要求,但是从最近的Facebook更新来看,我正在考虑。



原始哈希黑客(我是不知道这是否是正确的术语)是通过更改location.hash,可以在URL中保存状态,而不刷新页面。这是Google的应用程序,Facebook和最近#NewTwitter广泛使用的。但是今天我注意到,如果您使用现代浏览器(如chrome或firefox),Facebook将不再拥有#。我仔细检查一下,他们没有通过使用开发工具和firebug分别重新加载。



在stackoverflow中搜索最少,解决方案中最接近的是使用Flash - 但是禁用Flash和facebook.com仍然像一个魅力。
从chrome 8 dev和firefox 4 beta的覆盖面来看,我不知道这可能与HTML5时代的API有关,但是Facebook中的代码并不能调试来查找他们做了什么。 p>

既然这是我在这里问的第一个问题,我想知道你们中有没有人可能已经解决了这个问题。



谢谢你们。



PS在IE8上无效,尚未在IE9测试版上测试。

解决方案

Facebook正在使用HTML5中的历史API。从此博文,您可以看到它是如何工作的。基本上,他们正在打电话,如下所示更改url而不重新加载页面。

  window.history.pushState(object或字符串,标题,/ new-url); 

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



可惜的是,IE9不支持这个api。 Chrome和FF的新版本得到全面支持。


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

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.

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.

Thanks guys.

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

解决方案

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");

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

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

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

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