https://github.com/gr2m/has-localstorage
returns true if localStorage is supported _and_ persistent
https://github.com/gr2m/has-localstorage
Last synced: 4 months ago
JSON representation
returns true if localStorage is supported _and_ persistent
- Host: GitHub
- URL: https://github.com/gr2m/has-localstorage
- Owner: gr2m
- Created: 2015-01-02T13:49:45.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-03-05T06:41:15.000Z (over 5 years ago)
- Last Synced: 2026-02-11T16:06:35.521Z (5 months ago)
- Language: JavaScript
- Homepage: http://gr2m.github.io/has-localstorage/
- Size: 30 MB
- Stars: 6
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# has-localstorage
> returns true if localStorage is supported _and_ persistent
[](https://travis-ci.org/gr2m/has-localstorage/)
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.
## Downlaod or Installation
- Download [has-localstorage.js](https://raw.githubusercontent.com/gr2m/has-localstorage/master/lib/has-localstorage.js)
- or: install via Bower: `bower install --save has-localstorage`
- or: install via npm: `npm install --save has-localstorage`
## Usage
```js
if (hasLocalStorage()) {
// localStorage can be used, all data gets persisted
} else {
// localStorage is not available, or changes are not persisted
}
```
## Help wanted!
The current test setup is very simple: it only tests in latest Firefox
using Selenium and [Sauce Labs](http://saucelabs.com/). Unfortunately,
Sauce Labs has no support to start browsers in private mode, which would
be necessary, as `localStorage` behaves different if in private mode
in Safari, probably in other browsers as well.
If anynone has an idea to for that, ping me at
https://github.com/gr2m/has-localstorage/issues/1
# Acknowledgement
`hasLocalStorage()` has been inspired by this [Cappuccino](http://www.cappuccino-project.org/) commit:
https://github.com/cappuccino/cappuccino/commit/063b05d9643c35b303568a28809e4eb3224f71ec
## License
MIT