Reputation: 469
I want to use localStorage.setItem
in internet Explorer 11,
I tried like:
<script>
localStorage.setItem("lastname", "Smith");
</script>
but in IE console I see:
SCRIPT5007: Unable to get property 'setItem' of undefined or null reference.
I also tried the given answer like:
<script>
!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...");
}
</script>
but then I get:
Upvotes: 1
Views: 997
Reputation: 12961
localstorage
can't work with file://
protocal, you need to run the page through http protocal.localstorage
in old version of IE 11 in win7/win8, please make sure you have installed the latest update. Upvotes: 3