UNPKG

modernizr

Version:

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.

51 lines (44 loc) 1.47 kB
/*! { "name": "Local Storage", "property": "localstorage", "caniuse": "namevalue-storage", "tags": ["storage"], "knownBugs": [], "notes": [], "warnings": [], "polyfills": [ "joshuabell-polyfill", "cupcake", "storagepolyfill", "amplifyjs", "yui-cacheoffline" ] } !*/ define(['Modernizr'], function(Modernizr) { // In FF4, if disabled, window.localStorage should === null. // Normally, we could not test that directly and need to do a // `('localStorage' in window)` test first because otherwise Firefox will // throw bugzil.la/365772 if cookies are disabled // Similarly, in Chrome with "Block third-party cookies and site data" enabled, // attempting to access `window.sessionStorage` will throw an exception. crbug.com/357625 // Also in iOS5 Private Browsing mode, attempting to use localStorage.setItem // will throw the exception: // QUOTA_EXCEEDED_ERROR DOM Exception 22. // Peculiarly, getItem and removeItem calls do not throw. // Because we are forced to try/catch this, we'll go aggressive. // Just FWIW: IE8 Compat mode supports these features completely: // www.quirksmode.org/dom/html5.html // But IE8 doesn't support either with local files Modernizr.addTest('localstorage', function() { var mod = 'modernizr'; try { localStorage.setItem(mod, mod); localStorage.removeItem(mod); return true; } catch (e) { return false; } }); });