使用“使用“ localStorage.setItem” Internet Explorer”

问题描述 投票:0回答:1

我想在Internet Explorer 11中使用localStorage.setItem,>

我尝试过:

<script>
  localStorage.setItem("lastname", "Smith");
</script>

但是在IE控制台中,我看到:

SCRIPT5007:无法获取未定义或空引用的属性'setItem'。

我也尝试过given answer

<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>

但后来我得到:

enter image description here

我想在Internet Explorer 11中使用localStorage.setItem,我尝试过:

  • [请在IE 11中选中此选项,如果禁用此选项,则存储对象将在IE中未定义:
    1. 单击“工具”菜单,然后选择“ Internet选项”。
  • 单击标签为“高级”的选项卡。
  • 选中“ 启用DOM存储
  • ”框。
  • 单击“应用”,单击“确定”。
  • enter image description here

    • [localstorage不能与file://协议一起使用,您需要通过http协议来运行页面。
    • 在win7 / win8的IE 11的旧版本中可能有issueslocalstorage,请确保已安装最新更新。
    javascript local-storage internet-explorer-11
    1个回答
    0
    投票
    • [请在IE 11中选中此选项,如果禁用此选项,则存储对象将在IE中未定义:
      1. 单击“工具”菜单,然后选择“ Internet选项”。
    © www.soinside.com 2019 - 2024. All rights reserved.