【发布时间】:2012-12-14 01:35:43
【问题描述】:
下面的代码在 IE9 中给了我SCRIPT5009: 'Storage' is undefined。它适用于 Chrome、Safari、Firefox。
Storage.prototype.setObject = function(key, value) {
this.setItem(key, JSON.stringify(value));
}
udpate我从 Apache 服务器提供页面,而不是从本地文件系统访问它,因此以下内容不适用:
localStorage object is undefined in IE
local storage in IE9 fails when the website is accessed directly from the file system
update 2发现问题,看我的回答。
【问题讨论】:
-
页面上有 DOCTYPE 吗?页面是否在“兼容模式”下运行?
-
我没有指定 DOCTYPE。它正在运行“怪癖”模式
-
@dev.e.loper:这可能就是问题所在。它需要在“IE9模式”下运行。
-
我从 Apache 服务器提供页面,而不是从本地文件系统访问它
标签: javascript html