3

I want to replicate Local Storage concept (similar to HTML5) in javascript or jquery.

But unfortunately I don't have idea, how to start this.

Can any one suggest how to implement local storage using javascript or jquery (Without using HTML5)?

7
  • Why the restriction on HTML5? Commented Jan 2, 2012 at 5:39
  • You could use a flash proxy (use its local storage instead of HTML5's one) Commented Jan 2, 2012 at 5:40
  • You can't. JS can't access the filesystem, so where would your data be stored? Unless you want to use a cookie? Commented Jan 2, 2012 at 5:40
  • I have a restriction not use cookies and business wants to store the data on the browser location itself that is similar to HTML5. I can't use HTML5 for only this, since I need to support most of all browsers including old versions too. please suggest how best I can achieve this. Commented Jan 2, 2012 at 5:45
  • You'll have to tell whomever is setting the business requirements that it can't be done. Commented Jan 2, 2012 at 5:58

3 Answers 3

5

This is a bit of a fools errand because all modern browsers support localStorage and sessionStorage at this point. Its as simple as doing this:

sessionStorage.somesessionstorage = 'some session string value';
localStorage.somelocalstorage = 'some local storage value';

If you use this in conjunction with stringify to serialize and deserialize objects like so:

// serialize
sessionStorage.somesessionstorage = JSON.stringify(myObj);

// deserialize
var obj = JSON.parse(sessionStorage.somesessionstorage);

You can use cookies if you want to go against the grain and be silly. Otherwise, start to incorporate HTML5 features.

Keep in mind HTML5 is a big word and should not be in your head as describing everything. You should pick the more supported features over the less supported ones.

An incredible resource I love is the following website http://html5demos.com/ which very clearly lists out support in browsers. This will clear up your thinking.

Sign up to request clarification or add additional context in comments.

8 Comments

Local storage is not supported in IE6 or IE7 so if you want any compatibility with those browsers, you have to have a fallback method.
@jfriend00 Yes, you are correct. You could use Flash's storage option or cookies as worst case. However, you would have to question the business case to support older browsers in terms of percentage of traffic coming in. The numbers are dwindling far down on those browsers. IE 10 is practically out.
Numbers are dwindling, but still I happen to work in a place where everybody has to use IE7 - "everybody" in this case meaning thousands of users in this organisation. As recently as eighteen months ago I worked for a larger organisation that was still on IE6.
@nnnnnn I'm sorry. That sucks big time. I haven't had a boss for 7 years now so I guess I'm out of touch from having to be locked into a situation like that. I get to tell clients the browser support in my contracts and I show them the numbers and price difference it would cost to support lower versions and then they quickly opt out of supporting the lower versions as their current customer base is way too low in those older browsers.
@kitgui.com -- and that is the perfect approach. Let them see the $. If they insist on supporting IE6 and other legacy browsers, then they're going to have to pay for the volumes of hack-arounds to do so.
|
2

Try this jQuery plugin:

http://www.jstorage.info/

Will try various methods depending on the browser's capability.

EDIT:

And another (can use Flash/Silverlight/image based "cookies"):

http://samy.pl/evercookie/

4 Comments

Thanks paul. I have refered this site before I post it. But unfortunately JStorage makes use of HTML5 internally.
And if HTML5 isn't available, cookies are used. There's no other way (that I know of) to store data on the browser locally.
If the business requirement is no cookies then surely Evercookie (with or without flash/silverlight/etc options) isn't appropriate either.
Thanks all. I will suggest to business and let see.
0

You can use this jQuery plugin : https://github.com/julien-maurel/jQuery-Storage-API

But you'll always need cookies on old browser to simulate storage...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.