简体   繁体   English

Internet Explorer本地存储

[英]Internet Explorer Local Storage

I have a application which works great on all browsers but IE. 我有一个应用程序,适用于除IE之外的所有浏览器。 I am using the local database provided with HTML5. 我正在使用HTML5提供的本地数据库。 I need to store 3 attributes for the users of the application. 我需要为应用程序的用户存储3个属性。 I know in IE I can't use the database approach and I was thinking of using 3 arrays stored in local storage, one array for each attribute. 我知道在IE中我不能使用数据库方法,我想使用存储在本地存储中的3个数组,每个属性一个数组。 Is there a better (and easier) way of doing this? 这样做有更好(更简单)的方法吗?

Thanks 谢谢

For example, I want to store 1) destination 2) where they are from 3) date So I was thinking I will store an array for destinations, an array fro from locations and an array for dates. 例如,我想存储1)目的地2)它们来自3)日期所以我想我将存储目的地数组,来自位置的数组和日期数组。 Then using some id I can index the arrays and get the corresponding information. 然后使用一些id我可以索引数组并获取相应的信息。

If you need local storage, then you need local storage! 如果您需要本地存储,那么您需要本地存储! Based on the information you describe, I think it's probably too heavy to use in a session cookie. 根据您描述的信息,我认为在会话cookie中使用它可能太重了。

Check out the docs . 查看文档 Be aware that only IE8+ supports this, so if you need to support other versions - you'll need to do some extra work. 请注意,只有IE8 +支持此功能,因此如果您需要支持其他版本 - 您需要做一些额外的工作。

I would personally enable localStorage where possible, then fall back to a round-trip to the server if the browser doesn't support it (and the data is definitely too much for cookies). 我个人会在可能的情况下启用localStorage,如果浏览器不支持它,则会回到服务器的往返(并且数据对于cookie来说肯定是太多了)。

Update RE Polyfills 更新RE Polyfills

Keep in mind that the polyfills suggested by Rafael will fall back to cookies if the browser doesn't support localStorage etc. Be sure to test with a good spread of data, and keep in mind that it will be sending all that data with each request (which has it's own ramifications). 请记住,如果浏览器不支持localStorage等, Rafael建议的polyfill将回退到cookie。请务必使用良好的数据传播进行测试,并记住它将在每次请求时发送所有数据(它有它自己的分支)。

For IE, you can use a polyfill to simulate a native localStorage: https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills 对于IE,您可以使用polyfill来模拟本地localStorage: https//github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

LocalStorage uses a key:value system. LocalStorage使用密钥:值系统。 But you can save more than one data in one key, using JSON.Stringify & JSON.parse. 但是您可以使用JSON.Stringify和JSON.parse在一个密钥中保存多个数据。

localStorage in IE does not work with this url: file:///P:/Dropbox/abc_web/ingrid8/ingrid.htm#car.. IE中的localStorage无法使用此url:file:/// P:/Dropbox/abc_web/ingrid8/ingrid.htm#car ..

through network if it works: file://pedrojelp/p/Dropbox/abc_web/ingrid8/ingrid.htm#car.. 通过网络如果它工作:file://pedrojelp/p/Dropbox/abc_web/ingrid8/ingrid.htm#car ..

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

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