简体   繁体   English

使用Javascript / Jquery进行本地存储(不使用HTML5)

[英]Local Storage using Javascript / Jquery (Without using HTML5)

I want to replicate Local Storage concept (similar to HTML5) in javascript or jquery. 我想在javascript或jquery中复制本地存储概念(类似于HTML5)。

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)? 任何人都可以建议如何使用javascript或jquery(不使用HTML5)实现本地存储?

This is a bit of a fools errand because all modern browsers support localStorage and sessionStorage at this point. 这是一个愚蠢的差事,因为所有现代浏览器此时都支持localStorage和sessionStorage。 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: 如果你将它与stringify结合使用来序列化和反序列化对象,如下所示:

// 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. 如果你想要反对谷物并且愚蠢,你可以使用cookies。 Otherwise, start to incorporate HTML5 features. 否则,开始合并HTML5功能。

Keep in mind HTML5 is a big word and should not be in your head as describing everything. 请记住,HTML5是一个很重要的词,不应该在你的脑海中描述一切。 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. 我喜欢的一个令人难以置信的资源是以下网站http://html5demos.com/ ,它非常清楚地列出了浏览器的支持。 This will clear up your thinking. 这将清除你的想法。

Try this jQuery plugin: 试试这个jQuery插件:

http://www.jstorage.info/ http://www.jstorage.info/

Will try various methods depending on the browser's capability. 将根据浏览器的功能尝试各种方法。

EDIT: 编辑:

And another (can use Flash/Silverlight/image based "cookies"): 另一个(可以使用Flash / Silverlight /基于图像的“cookies”):

http://samy.pl/evercookie/ http://samy.pl/evercookie/

You can use this jQuery plugin : https://github.com/julien-maurel/jQuery-Storage-API 你可以使用这个jQuery插件: https//github.com/julien-maurel/jQuery-Storage-API

But you'll always need cookies on old browser to simulate storage... 但是你总是需要在旧浏览器上使用cookie来模拟存储......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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