I am trying to use the HTML5 feature
'localStorage is null or not an object'
So my question: can
localStorage be used by IE8 out-of-the-box? Here is my code:
It does support
localStorage, though you need to be in IE8 mode (this will not work in IE7 mode).
To check that you're working in IE8 mode, load up the developer console. At the top, make sure that IE8 mode is selected. Standards mode would also be nice.
One thing that you also want to make sure of is that you're using the HTML5 doctype. You shouldn't be able to use an XHTML doctype with HTML5 features.
Using this doctype should not impact your browser support.
Also, make sure you access
window.localStorage. It shouldn't be an issue, but IE has been known to host weirder issues. Perhaps it's looking for a locally scoped
localStorage object? Who knows.
the comment of musicfreak was correct. Because this feature requires domain, I had to use it only through a live url (at least localhost) and not by opening it as a file from a disk.
There is no need to add
window.localStorage as IE8 recognizes just
localStorage as well.
Expanding upon a previous good Answer:
I had this same problem --worse! even IE10 failed!-- and I discovered the solution (for me) had more to do with my development environment than Internet Explorer. What I had done was create an HTML file, and edit it a lot using a good text editor. I could click-drag the file into a browser to see my progress in developing the page, and later simply refresh the browser window, when I updated/edited various things in the file.
It turns out that for Chrome and Firefox and Opera, window.localStorage was a valid object, but for Internet Explorer, it was "undefined" (as seen in the debugger). However, once I fired up a Web Server program (for "localhost"), and used that to feed the HTML page to the browser, then Internet Explorer provided a valid object ("DispHTMLStorage") for window.localStorage. Also note that in Tools/Options/Advanced for IE, there is a checkbox "enable DOM storage" --it appears to be checked by default, but it is always possible that some user will have manually disabled it.
Try using "IE=edge" instead of "IE=8" in your x-ua-compatible meta tag
From Microsoft: (link)
Use the following value to display the webpage in EdgeHTML mode, which is the highest standards mode supported by Internet Explorer, from Internet Explorer 6 through IE11.
<meta http-equiv="x-ua-compatible" content="IE=edge" >
Local storage concept should work on IE8+.
All you have to do is put your source code on the server and run it.
©2020 All rights reserved.