Created
November 12, 2015 12:12
-
-
Save antoine-pous/c73e5a3a3b1e9507597d to your computer and use it in GitHub Desktop.
Check if the localStorage is available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* "THE BEER-WARE LICENSE" (Revision 42): | |
* <[email protected]> wrote this file. As long as you retain this notice you | |
* can do whatever you want with this stuff. If we meet some day, and you think | |
* this stuff is worth it, you can buy me a beer in return Antoine "Gecko" Pous | |
*/ | |
LSChecker = function() { | |
try { | |
localStorage.setItem('test', 'test'); | |
localStorage.removeItem('test'); | |
return true; | |
} catch(e) { | |
return false; | |
} | |
} | |
// Usage : | |
if(LSChecker()) { | |
//... do the stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is much better: