returns true if localStorage is supported and persistent
returns true
or false
depending on whether localStorage is supported or not.
Beware that some browsers like Safari do not support localStorage in private mode.
Download has-localstorage.js or has-localstorage.min.js.
Install via Bower
bower install -S has-localstorage
Install via npm
npm install -S has-localstorage
if (hasLocalStorage()) {
// localStorage can be used, all data gets persisted
} else {
// localStorage is not available, or changes are not persisted
}
hasLocalStorage()
has been inspired by this Cappuccino commit:
https://github.com/cappuccino/cappuccino/commit/063b05d9643c35b303568a28809e4eb3224f71ec
MIT