Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 552
Niels Avatar asked Sep 03 '15 11:09

Niels


2 Answers

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.

like image 145
nils Avatar answered Nov 10 '22 13:11

nils


Could you please try

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

Could you also check if you have 'Enable DOM Storage' selected? You can find it under: Internet Options -> Advanced tab -> Security group box

Also if you are running your page from local filesystem, localStorage doesn't work on IE, you have to run it from the web server.

Here is a link that provides more information of how to enable it

like image 38
Vlad Bezden Avatar answered Nov 10 '22 12:11

Vlad Bezden