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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.