localStorage not supported by IE9?

10,920

Local Storage is stored relative to an origin.

This means you must open your page using http://someorigin/pathtoyourpage.html. It can't work on IE if you're opening the page in file://pathtoyourpage.html (and shouldn't work on other browsers).

So you need to access your page using a web server (it can be on localhost).

Share:
10,920
Valeriane
Author by

Valeriane

Updated on June 16, 2022

Comments

  • Valeriane
    Valeriane about 2 years

    Everybody say that window.localStorage is supported by IE (until IE8)

    I test it on IE9 but :

    console.log(typeof window.localStorage)
    
    undefined
    

    what does it mean?

    What's the best way to store local data for all browser?

  • Valeriane
    Valeriane over 11 years
    I have no server, I am developping a client side appliation with html5, is not possible to store data in this case?
  • Denys Séguret
    Denys Séguret over 11 years
    You mean you can't install a simple http server ? In this edge case you won't be able to use localStorage in your pages.
  • Valeriane
    Valeriane over 11 years
    I can't install http server, It is not the purpose of my project
  • Denys Séguret
    Denys Séguret over 11 years
    The web has be designed for the network, not for local file access, hence this kind of limits. But if your users can call a website once to fetch your site, your solution might be to use HTML5's application cache.
  • mkoryak
    mkoryak over 11 years
    @valeri if the purpose of your project is to make a working website, you might want to reconsider that little detail about the server.
  • mercator
    mercator over 11 years
    This answer is incorrect. Firefox, Chrome and Opera support localStorage just fine on the local file system. Firefox seems to be a bit more restrictive than the others, only sharing storage between files in the same directory. IE doesn't support it at all, presumably for security reasons.
  • Denys Séguret
    Denys Séguret over 11 years
    I know they "support" it. Read my answer again. I said they "shouldn't" because this is a security breach leading to leaks between local applications. And, probably more importantly, this uselessly clutters the local localstorage. Note that the official w3.org spec regarding the local origin is clearly vague which leads to a few differences between browsers. For most other purposes (for example requests) even Chrome and Firefox consider 2 pages coming from file:// to be of different origins.
  • mercator
    mercator over 11 years
    Your answer says nothing about security, but instead seems to say that storage needing an origin precludes local use. file: URLs also have an origin.