HTML5本地存储回退解决方案 [英] HTML5 Local Storage fallback solutions

查看:225
本文介绍了HTML5本地存储回退解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找可以在不具有原生支持的浏览器上模拟 localStorage 的JavaScript库和代码。



基本上,我想使用 localStorage 编写我的网站来存储数据,并知道它仍然可以在本地不支持它的浏览器上工作。这意味着一个库会检测是否存在 window.localStorage ,如果有的话就使用它。如果它不存在,那么它将通过在 window.localStorage 命名空间中创建自己的实现来创建某种本地存储的回退方法。



到目前为止,我已经找到了这些解决方案:


  1. 简单
  2. 一个实现
  3. href =http://www.thewojogroup.com/2010/01/simulating-html5-local-storage/ =noreferrer>使用cookies (对此并不兴奋) >
  4. Dojo的 dojox.storage ,但这是它自己的事情,不是真的是一个后备。

据我所知,Flash和Silverlight也可以用于本地存储,但没有发现任何东西他们作为标准的HTML5 localStorage的后备。也许Google Gears也有这个功能吗?



请分享您找到的任何相关的图书馆,资源或代码片段!我会特别感兴趣的纯粹的JavaScript或基于jQuery的解决方案,但我猜这是不可能的。

一个href =http://pablotron.org/?cid=1557 =noreferrer> PersistJS ( github仓库),它可以无缝,透明地处理客户端存储。您使用单个API并获得对以下后端的支持:


  • flash:Flash 8持久性存储。

  • 档位:基于Google Gears的持久存储。

  • localstorage:HTML5草稿存储空间。

  • whatwg_db:HTML5草稿数据库存储。

  • globalstorage:HTML5草稿存储(旧规格)。

  • ie:Internet Explorer用户数据行为。

  • cookie:基于Cookie的持久性存储。



其中任何一个都可以被禁用— if例如,你不想使用cookies。借助这个库,您将在IE 5.5+,Firefox 2.0 +,Safari 3.1+和Chrome中获得本机客户端存储支持;和如果浏览器有Flash或Gears插件辅助支持。如果你启用了cookies,它将在任何情况下都能正常工作(但是将被限制在4 kB)。

I'm looking for javascript libraries and code that can simulate localStorage on browsers that do not have native support.

Basically, I'd like to code my site using localStorage to store data and know that it will still work on browsers that don't natively support it. This would mean a library would detect if window.localStorage exists and use it if it does. If it doesn't exist, then it would create some sort of fallback method of local storage, by creating its own implementation in the window.localStorage namespace.

So far, I've found these solutions:

  1. Simple sessionStorage implementation.
  2. An implementation that uses cookies (not thrilled with this idea).
  3. Dojo's dojox.storage, but it is it's own thing, not really a fallback.

I understand that Flash and Silverlight can be used for local storage as well, but haven't found anything on using them as a fallback for standard HTML5 localStorage. Perhaps Google Gears has this capability too?

Please share any related libraries, resources, or code snippets that you've found! I'd be especially interested in pure javascript or jquery-based solutions, but am guessing that is unlikely.

解决方案

I use PersistJS (github repository), which handles client-side storage seamlessly and transparently to your code. You use a single API and get support for the following backends:

  • flash: Flash 8 persistent storage.
  • gears: Google Gears-based persistent storage.
  • localstorage: HTML5 draft storage.
  • whatwg_db: HTML5 draft database storage.
  • globalstorage: HTML5 draft storage (old spec).
  • ie: Internet Explorer userdata behaviors.
  • cookie: Cookie-based persistent storage.

Any of those can be disabled—if, for example, you don't want to use cookies. With this library, you'll get native client-side storage support in IE 5.5+, Firefox 2.0+, Safari 3.1+, and Chrome; and plugin-assisted support if the browser has Flash or Gears. If you enable cookies, it will work in everything (but will be limited to 4 kB).

这篇关于HTML5本地存储回退解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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