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

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

问题描述

我正在寻找可以在没有本机支持的浏览器上模拟 localStorage 的 javascript 库和代码.

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

基本上,我想使用 localStorage 对我的网站进行编码以存储数据,并且知道它仍然可以在本身不支持它的浏览器上运行.这意味着库将检测 window.localStorage 是否存在并在存在时使用它.如果它不存在,那么它将通过在 window.localStorage 命名空间中创建自己的实现来创建某种本地存储的后备方法.

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. 简单的sessionStorage实现.
  2. 使用 cookie 的实现(对这个想法).
  3. Dojo 的 dojox.storage,但它是它自己的东西,并不是真正的后备.
  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.

我知道 Flash 和 Silverlight 也可用于本地存储,但还没有发现将它们用作标准 HTML5 localStorage 的后备.也许 Google Gears 也有这个功能?

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?

请分享您找到的任何相关库、资源或代码片段!我对纯 javascript 或基于 jquery 的解决方案特别感兴趣,但我猜这不太可能.

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.

推荐答案

我使用 PersistJS (<一个 href="https://github.com/jeremydurham/persist-js" rel="noreferrer">github 存储库),它可以无缝且透明地处理您的代码的客户端存储.您使用单个 API 并获得对以下后端的支持:

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 持久存储.
  • gears:基于 Google Gears 的持久存储.
  • localstorage:HTML5 草稿存储.
  • whatwg_db:HTML5 草稿数据库存储.
  • globalstorage:HTML5 草稿存储(旧规范).
  • 即:Internet Explorer 用户数据行为.
  • cookie:基于 Cookie 的持久存储.

可以禁用其中任何一个——例如,如果您不想使用 cookie.使用这个库,您将在 IE 5.5+、Firefox 2.0+、Safari 3.1+ 和 Chrome 中获得原生客户端存储支持;如果浏览器具有 Flash 或 Gears,则支持插件辅助.如果您启用 cookie,它将适用于所有内容(但限制为 4 kB).

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天全站免登陆