Does IE8 out-of-the-box have support for 'localStorage'

I am trying to use the HTML5 feature localStorage. According to this blog it can be done using IE8, however when I try to use it I get a javascript error 'localStorage is null or not an object'

So my question: can localStorage be used by IE8 out-of-the-box? Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>IE8 - DOM Storage</title>
    <script type="text/javascript"> 
        function Save() {
            localStorage.setItem('key','value');            
        }        
    </script>
</head>
<body>        
    <button onclick="Save();">
        Save
    </button>  
</body>
</html>

Answers:

Answer

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.

<!DOCTYPE html>

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.

Answer

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.

Answer

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.

Answer

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" >
Answer

Local storage concept should work on IE8+.

All you have to do is put your source code on the server and run it.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.