Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@RwwL
Copy link

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.

@paulirish
Copy link
Member

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.

@paulirish
Copy link
Member

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

paulirish added a commit to SlexAxton/Modernizr that referenced this issue May 26, 2011
patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants