简体   繁体   中英

Is there a wrapper for HTML5 sessionStorage that provides a good compatability implementation?

We would like to use the HTML5 sessionStorage (or something like it) in a new project but you can't rely on it on some browsers. There's this project ( http://code.google.com/p/sessionstorage/ ) which provides an implementation that works a lot of places, yet oddly it doesn't use the HTML5 version if it is available. It always does its own thing.

There's this project ( https://github.com/jas-/jQuery.handleStorage ) over on GitHub but its emulation layer is cookies (bleh!) .

Note: The above is incorrect, see the answer from jas- below where he explains that I was mistaken about that project.

Is there anything better out there that offers a good implementation like the first project but falls back automatically to HTML5 if it is available? We might retrofit the first project to automatically fall back to HTML5 if available but would rather not build that if there's already a good solution out there.

Munsch,

I realize this post is several years old but I wanted to clarify the project you mentioned, I am the author of jQuery.handleStorage and it does not use cookies as its default method of client storage.

If you read the documentation for the project you will see that one of its three client storage options is to use cookies in the event a clients browser does not support the HTML5 localStorage and/or sessionStorage API's.

With that said, if you need a more robust and flexible client storage tool I would recommend secStore.js as it does not implicitly require binding to a form, supports the HTML5 client storage options, gracefully degrades to cookie in the event of a legacy browser and optionally uses the SJCL API to provide transparent encryption of possible sensitive data.

I know you said that you wanted a solution that did it all but what's wrong with something like this?

if(!window.sessionStorage){
    $.getScript("/google_code_sessionStorage.js");
}

There's a couple of YUI utilities for this, depending on whether you're using 2 or 3:

Both will use HTML5 session storage if available.

I ended up doing more research on this because I liked both of the answers I got, but I wanted something more like the YUI 3: Storage Lite but that didn't require YUI. Something that was framework agnostic or jQuery friendly would work a lot better for us.

In the end I found a couple of possibilities and one stood out as what we'll try and put to use: Lawnchair

Also considered: store.js , AmplifyJS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM