/    Sign up×
Community /Pin to ProfileBookmark

LocalStorage Doesn’t Work on IE10

I can’t get LocalStorage to work on Internet Explorer 10.

The following test code (from [url]http://www.w3schools.com/html/html5_webstorage.asp[/url]) works on Chrome and Safari.

[CODE]<!DOCTYPE html>
<html>
<body>

<div id=”result”></div>
<script>
if(typeof(Storage)!==”undefined”)
{
localStorage.lastname=”Smith”;
document.getElementById(“result”).innerHTML=”Last name: ” + localStorage.lastname;
}
else
{
document.getElementById(“result”).innerHTML=”Sorry, your browser does not support web storage…”;
}
</script>

</body>
</html>[/CODE]

When I try it on IE10 I get the following error:

SCRIPT5007: Unable to set property ‘lastname’ of undefined or null reference

The code first checks for browser support which IE10 shows positive.

I’ve tried windows.localStorage and document.localStorage without any luck.
In Options/Advanced menu, Enable local DOM storage is checked.

Any other tweaking I need to do to get it to work?

Thanks,

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@sQu1rrJun 10.2013 — Are you using <!doctype html> ?
Copy linkTweet thisAlerts:
@Logic_AliJun 10.2013 — [FONT=courier new]window.Storage[/FONT] indicates browser support but not necessarily that it will work under the current protocol. It wont under file:// protocol.

You could test [FONT=courier new]window.localStorage[/FONT]
Copy linkTweet thisAlerts:
@TcobbJun 11.2013 — Have you tried using the getter/setter functions? Does that work?

As in :

[CODE]var x = localStorage.getItem(key);
localStorage.setItem(key, data);[/CODE]
Copy linkTweet thisAlerts:
@TedNauthorJun 11.2013 — Thanks for replies.

sQ1rr - Yes, I am using <!doctype html>

Logic Ali - It would seem you're right regarding file:// protocol. I can get the code to work if I download the page from my server. But it won't work from my local drive. Safari and Chrome work either way. Do you know of any way to get IE10 working from local drive?

I'd already tried window.localStorage. window[B]s[/B].localStorage was a typo.

I tried placing everything in a function and using [I]return[/I] but I still got the same error.

Tcobb - I tried the get and set functions but they bring up similar errors.

The problem seems to be that IE10 doesn't like using localStorage with a webpage on a local drive. Anyone know of a work around would be great.

Thanks,
Copy linkTweet thisAlerts:
@Logic_AliJun 12.2013 — 

Logic Ali - It would seem you're right regarding file:// protocol. I can get the code to work if I download the page from my server. But it won't work from my local drive. Safari and Chrome work either way. Do you know of any way to get IE10 working from local drive?
[/QUOTE]
Install a local server like Apache or IIs


I'd already tried window.localStorage. window[B]s[/B].localStorage was a typo.

I tried placing everything in a function and using [I]return[/I] but I still got the same error.[/quote]

Under file:// protocol this does not produce an error on I.E.
[CODE]<!DOCTYPE html>
<html>
<body>

<div id="result"></div>
<script>

var outputElem = document.getElementById("result");

if( typeof( window.localStorage) !== "undefined" )
{
localStorage.setItem( 'lastname', "Smith" );
outputElem.innerHTML="Last name: " + localStorage.lastname;
}
else
{
outputElem.innerHTML="Sorry, your browser does not support web storage...";
}

</script>

</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@TedNauthorJun 13.2013 — Lol.

I copied your above script and now I get the message, "Sorry, your browser does not support web storage..."

However, I had also reset ie10 to default values so that might be a problem. Luckily my need is such that I can be browser specific, so I don't have to use IE. I'll play around with this a bit more but if I don't have any luck I'll use Chrome or Safari.

Incidentally, you mentioned earlier that local storage wouldn't work on file:// protocol. So how would the above code work?

Thanks,
Copy linkTweet thisAlerts:
@Logic_AliJun 13.2013 — Lol.

I copied your above script and now I get the message, "Sorry, your browser does not support web storage..."

However, I had also reset ie10 to default values so that might be a problem. Luckily my need is such that I can be browser specific, so I don't have to use IE. I'll play around with this a bit more but if I don't have any luck I'll use Chrome or Safari.

Incidentally, you mentioned earlier that local storage wouldn't work on file:// protocol. So how would the above code work?

Thanks,[/QUOTE]
It won't make localStorage work locally, it will just tell you that it doesn't. As I indicated previously, if you want to test localStorage routines locally you must install a server.
Copy linkTweet thisAlerts:
@TedNauthorJun 13.2013 — OK Logic Ali. I see what you're saying, and why I got the message.
×

Success!

Help @TedN spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...