localStorage and sessionStorage test true in IE on locally-served pages #143

Closed
RwwL opened this Issue Nov 10, 2010 · 2 comments

Comments

Projects
None yet
2 participants

RwwL commented Nov 10, 2010

IE8's default settings don't allow the use of cookies or local/session storage on pages served from the hard drive, even after you "Allow Blocked Content" to allow JavaScript execution. So when viewing C:\Documents and Settings\username\filename.html, Modernizr 1.6 will test true for localStorage or sessionStorage, but attempts to get or set storage items will result in "is null or not an object" errors because the window.localStorage/window.sessionStorage will return undefined in this case.

It's pretty easy to work around this:

tests['localstorage'] = function() {
    try {
      return ('localStorage' in window) && window['localStorage'] && window.localStorage !== null;
    } catch(e) {
      return false;
    }
};

tests['sessionstorage'] = function() {
    try {
        return ('sessionStorage' in window) && window['sessionStorage'] && window.sessionStorage !== null;
    } catch(e){
        return false;
    }
};

Kind of an edge case, but I'm currently working on a toolkit of web controls that's specifically intended to be distributed as a ZIP and run locally, and accounting for this offline context was helpful.

Owner

paulirish commented Nov 10, 2010

Thx for the suggestion.. we can actually revise this test since it uses a try/catch anyway.. something we should do.
thanks for the help.. we'll incorporate this fact into the inline docs.

Owner

paulirish commented Dec 7, 2010

IE8 doesnt support localStorage with local files. new test accounts for this. closed by c0c542d

@paulirish paulirish added a commit to SlexAxton/Modernizr that referenced this issue May 26, 2011

@paulirish paulirish IE8 doesnt support localStorage with local files. new test accounts f…
…or this. fixes #143
c0c542d

@patrickkettner patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015

@paulirish paulirish IE8 doesnt support localStorage with local files. new test accounts f…
…or this. fixes #143
a6ad846

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment