I'm using localStorage in my JS application and I was wondering why IE9 claims localStorage == undefined
. As far as I know, IE8 supports it, is here any way to get it working in the new version?
localStorage object is undefined in IE
Asked Answered
Are you testing this on a local HTML file? i.e. a file:///
URL?
localStorage is only available on HTTP websites. That hasn't changed in IE9 Dev Preview.
@AJ. Thanks. I had a suspicion that was the issue, but was still wondering what was wrong when testing in IE. I started running my test page from within an web app and it worked just fine across IE, FF and Chrome. –
Ryle
IE 11 WORKS
All you need two do add file://127.0.0.1 to the trusted zones under the security tab (NOTE: make sure https check box IS not checked) add this line to the top or your script, depending on your code you may not need to unless you get could not connect to the internet.
!localStorage && (l = location, p = l.pathname.replace(/(^..)(:)/, "$1$$"), (l.href = l.protocol + "//127.0.0.1" + p));
if (typeof(Storage) != "undefined") {
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
alert(localStorage.getItem("lastname"));
} else {
alert("Sorry, your browser does not support Web Storage...");
}
Great, this works! On my machine even without changing anything in the Security tabs etc. One note: this code throws a
Variable undefined in strict mode
error if you execute your code in strict mode. To solve, re-write in non-condensed mode (if (!localStorage) { .... }
) –
Byline Try to open the file like this
file://127.0.0.1/c$/pathtofile/file.html
I don't think that works. Couldn't get it to work in IE11, at least. Ah, well, use mongoose web server, it is small enough and then localSTorage works. –
Formative
@daylight It works if you also add
file://127.0.0.1
to the list of trusted sites. –
Tetra On IE11, this does not seem to work. I can't access a local file using
file://127.0.0.1/...
. I've add file://127.0.0.1
to the IE Trusted Sites list. –
Fibrosis Worked for me on IE11 –
Landwehr
© 2022 - 2024 — McMap. All rights reserved.
file://
protocol? – BremserlocalStorage
in the Dev Tools console of the Platform Preview works for me on http sites – Bremser