localStorage无法在Edge工作? [英] localStorage not working in Edge?

查看:202
本文介绍了localStorage无法在Edge工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究一些JS。它在除Microsoft Edge之外的每个浏览器中都能正常工作。
问题非常简单:在我的一个脚本开头的
我声明了一个如下变量:

I am currently working on a some JS. It works fine in every browser apart from Microsoft Edge. The issue is quite simple: at the beginning of one of my scripts I declare a variable like so:

var something = localStorage.getItem('something'); 

无论如何这个东西还不存在,但整个想法是这个可以用来参考在后来的功能中。 Firefox,Chrome,Opera和Safari没有这个问题,但Edge确实存在问题,所以我的问题是,这是一个快速解决方案吗?
或者我是否因为Edge而不得不重写我的整个脚本?

Anyway the something doesn't exist yet, but the whole idea is that this can be used for reference in a later function. Firefox, Chrome, Opera and Safari don't have a problem with this but Edge does, so my question is, is the a quick fix? Or am i going to have to rewrite my whole script because of Edge?

这是边缘抛出的错误。

 Unable to get property 'getItem' of undefined or null reference

谢谢!

推荐答案

本地存储不适用于IE9中的本地文件,所以我想这仍然是MS Edge中的案例。

Local Storage didn't work for local files in IE9, so I imagine that this is still the case in MS Edge.

我刚刚在Edge中使用 localhost 上的服务器对其进行了测试,并且您的代码行工作正常很好:

I just tested it in Edge with a server on localhost and your line of code worked just fine:

> var something = localStorage.getItem('something');
> undefined

这可能是早期版本IE中的安全问题,并且从未更新为浏览器是开发的。

It is possible that this was a security issue in earlier versions of IE and was just never updated as the browser was developed.

虽然看起来localStorage和sessionStorage仍无法在使用'file://'协议访问的HTML文件的边缘。

Although, it appears that localStorage and sessionStorage still don't work in Edge for HTML files accessed using the 'file://' protocol.

这篇关于localStorage无法在Edge工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆