Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

javascript - localStorage not working in 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'); 

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?

This is the error that edge throws by the way.

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

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...