Facebook聊天框不会在页面之间重新加载 [英] Facebook chatbox doesn't reload between pages

查看:116
本文介绍了Facebook聊天框不会在页面之间重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Facebook上观察到这个功能,当你在右下方打​​开一个聊天框,然后你去另一个页面,比如你的朋友的个人资料,或Facebook内的一些照片收集页面时,聊天框不会重新加载,它仍然保留在它的位置(好像在背景页面顶部的一个单独的层中)。

I observed this feature in Facebook, that when you have a chat box opened at the bottom right, and you go to another page, say, your friend's profile, or some photo collection page within Facebook, the chat box doesn't reload, it remains where it is (as if in a separate layer on top of the background page).

很自然地,我认为Facebook没有重新加载页面本身,它使用 history.pushstate 和相关函数异步加载内容,并动态更改URL(Firebug确认,如果你点击你朋友的名字之一并被带到你朋友的个人资料页面,它实际上是一个 GET 请求被解雇了)。因此,由于没有任何页面加载,聊天框可以暂时闲置。

So naturally, I thought that Facebook isn't reloading the page per se, it is using history.pushstate and related functions to load the content asynchronously, and changing the URL dynamically (Firebug confirmed it, if you click on one of your friend's name and is taken to your friend's profile page, it is actually a GET request that is getting fired). So since there isn't exactly any page loading, the chatbox can just lay idle, as it is.

然而, pushstate IE 不支持$ c>。但是,它在 IE9 中也能正常工作。所以有人能告诉我他们是怎么做到的吗?他们是否使用历史 API或其他不同的东西?

However, pushstate isn't supported by IE prior to version 10. Still, it works just fine in IE9 as well. So can anyone tell me how are they doing it? Are they using the history API at all, or something different?

推荐答案

这是一个很简单的答案的好问题。我不确定Facebook,但这应该对你有帮助 - History.js

That's a great question with a simply answer. I'm not sure about Facebook, but this should help you - History.js


History.js在所有浏览器中优雅地支持HTML5历史/状态API(pushState,replaceState,onPopState)。包括对数据,标题,replaceState的持续支持。支持jQuery,MooTools和Prototype。对于HTML5浏览器,这意味着您可以直接修改URL,而无需再使用哈希。对于HTML4浏览器,它将恢复使用旧的onhashchange功能。

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

这篇关于Facebook聊天框不会在页面之间重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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