Facebook chatbox doesn't reload between pages

断了今生、忘了曾经 提交于 2019-12-21 05:12:23

问题


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).

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.

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/15597021/facebook-chatbox-doesnt-reload-between-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!