javascript IE9 不支持本地存储?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13305131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:21:41  来源:igfitidea点击:

localStorage not supported by IE9?

javascripthtmlinternet-explorerlocal-storage

提问by Valeriane

Everybody say that window.localStorageis supported by IE (until IE8)

大家都说window.localStorageIE支持(直到IE8)

I test it on IE9 but :

我在 IE9 上测试它但是:

console.log(typeof window.localStorage)

undefined

what does it mean?

这是什么意思?

What's the best way to store local data for all browser?

为所有浏览器存储本地数据的最佳方式是什么?

回答by Denys Séguret

Local Storage is stored relative to an origin.

本地存储是相对于 origin存储

This means you must open your page using http://someorigin/pathtoyourpage.html. It can't work on IE if you're opening the page in file://pathtoyourpage.html(and shouldn't work on other browsers).

这意味着您必须使用http://someorigin/pathtoyourpage.html. 如果您在 IE 中打开页面,则它无法在 IE 上工作file://pathtoyourpage.html(并且不应在其他浏览器上工作)。

So you need to access your page using a web server (it can be on localhost).

因此,您需要使用 Web 服务器(它可以在本地主机上)访问您的页面。

回答by Valeriane

What about Storage.js ?

Storage.js 呢?

https://sites.google.com/site/daveschindler/jquery-html5-storage-plugin

https://sites.google.com/site/daveschindler/jquery-html5-storage-plugin

"Provides a simple interface for storing data such as user preferences. The storage plugin is useful for saving and retreiving data from the user's browser. For newer browsers, HTML 5's localStorage is used. If localStorage isn't supported, then cookies are used instead. Retrievable data is limited to the same domain. "

"提供了一个简单的界面来存储用户首选项等数据。存储插件对于从用户浏览器保存和检索数据很有用。对于较新的浏览器,使用 HTML 5 的 localStorage。如果不支持 localStorage,则使用 cookie . 可检索的数据仅限于同一个域。”