javascript 在 IE11 中对 localStorage 的访问被拒绝,但仅在桌面模式下(不在地铁模式下)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20212627/
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-27 18:01:00  来源:igfitidea点击:

Access denied for localStorage in IE11 but only in desktop mode (not in metro mode)

javascriptlocal-storagewindows-8.1internet-explorer-11

提问by primavera133

So I have a site running on Adobe AEM 5.6.1 which checks if localStorage is accessible. The problem for me is it breaks with an "Access Denied" when I access the site from the Desktop version of IE11 (on a HP Elite Pad 900, running windows 8.1 Pro). On the same device it works fine using the metro mode version of IE11.

所以我有一个在 Adob​​e AEM 5.6.1 上运行的站点,它检查 localStorage 是否可访问。对我来说,问题是当我从 IE11 的桌面版本(在运行 Windows 8.1 Pro 的 HP Elite Pad 900 上)访问站点时,它会因“拒绝访问”而中断。在同一台设备上,它使用 IE11 的 Metro 模式版本可以正常工作。

It also works fine on at least two other computers here, one native PC, one virtualbox:ed on my mac.

它也可以在至少两台其他计算机上正常工作,一台本机 PC,一台 virtualbox:ed 在我的 Mac 上。

I know you are not allowed to access localStorage when running a local html-file but this is running on our server.

我知道在运行本地 html 文件时不允许您访问 localStorage,但这是在我们的服务器上运行的。

What could be different in access rights/security settings for the non-functional browser? Is there any way of checking this programmatically with javascript?

非功能性浏览器的访问权限/安全设置有何不同?有没有办法用javascript以编程方式检查这个?

采纳答案by primavera133

The way to check for local storage programmatically in JS seems to be to always use a try-catch:

在 JS 中以编程方式检查本地存储的方法似乎总是使用 try-catch:

http://mathiasbynens.be/notes/localstorage-pattern#comment-9

http://mathiasbynens.be/notes/localstorage-pattern#comment-9