我希望我的网页允许用户添加数据,即使他处于离线模式并且可能将数据存储在本地存储(cookies、html5 存储)中。当用户再次上线时,页面应检测实时连接并将数据发布到服务器。
是否有主流方法可以做到这一点?也许是 JavaScript 库或插件?
最佳答案
- 将您的(json 化)数据保存在 html5 本地存储中(或使用像 persistJS 这样的库以获得完整的跨浏览器支持,see this blogpost for an example on storing structured data this way)
- 有一个后台进程检查浏览器是否在线以与服务器同步(参见 this article on hacks.mozilla.org for an example of online syncing)。
关于javascript - 当连接可用时,将我的网页与服务器同步(也称为离线模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2465211/