Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local Storage using Javascript / Jquery (Without using HTML5)

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)?

like image 738
Siva Charan Avatar asked Feb 22 '26 15:02

Siva Charan


1 Answers

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.

like image 172
King Friday Avatar answered Feb 25 '26 04:02

King Friday



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!