gpt4 book ai didi

javascript - IE9 中未定义“存储”

转载 作者:行者123 更新时间:2023-11-28 02:31:33 26 4
gpt4 key购买 nike

Possible Duplicate:
localStorage object is undefined in IE

下面的代码给了我SCRIPT5009: 'Storage' is undefined在IE9中。它适用于 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

更新2发现问题,请参阅我的回答。

最佳答案

发现问题了。我必须指定 DOCTYPE <!DOCTYPE html>即使其他浏览器不关心 IE 也不关心。

感谢@Rocket Hazmat 指出这一点。

如果没有 DOCTYPE,IE 将进入 Quirks 模式。使用 DOCTYPE,IE 将进入标准模式。我的猜测是 IE 需要处于标准模式才能访问 HTML5 功能。

关于javascript - IE9 中未定义“存储”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14075399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com