javascript - 使用“localStorage.setItem”Internet Explorer
问题描述
我想localStorage.setItem
在 Internet Explorer 11 中使用,
我试过像:
<script>
localStorage.setItem("lastname", "Smith");
</script>
但在 IE 控制台中我看到:
SCRIPT5007:无法获取未定义或空引用的属性“setItem”。
我还尝试了给定的答案,例如:
<script>
!localStorage && (l = location, p = l.pathname.replace(/(^..)(:)/, "$1$$"), (l.href = l.protocol + "//127.0.0.1" + p));
if (typeof(Storage) != "undefined") {
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
alert(localStorage.getItem("lastname"));
} else {
alert("Sorry, your browser does not support Web Storage...");
}
</script>
但后来我得到:
解决方案
- 请在 IE 11 中勾选此选项,如果禁用此选项,存储对象将在 IE 中未定义:
- 单击“工具”菜单并选择“Internet 选项”。
- 单击标有“高级”的选项卡。
- 选中“启用 DOM 存储”复选框。
- 单击“应用”,单击“确定”。
localstorage
无法使用file://
协议,您需要通过 http 协议运行页面。- win7/win8的旧版IE 11可能存在问题,请确保您已安装最新更新。
localstorage
推荐阅读
- c# - 如何在openXml中找到最后一段的页行位置?(在最后一段之后的最后一页的word文档中可用多少空间)
- go - 如何列出网络中的所有 IP
- android - 如何使微调器中的 int 值显示为微调器内 UI 中的文本值?
- loops - Ansible:提取路径循环查找
- regex - 限制单词中的字符序列重复
- javascript - 根据 React Hooks 中父组件的不同变化,改变子组件的不同 props?
- informatica - 在 Informatica 中,如何忽略出现在表的某一列中的逗号
- ios - Cordova 电话链接在 iPhone X 上不起作用
- apache-spark - 关系化 json 嵌套数组
- database - Oracle 管理员帐户(SYS 和 SYSTEM)的默认密码是什么?