Skip to content

Instantly share code, notes, and snippets.

@haribote
Last active August 29, 2015 13:58
Show Gist options
  • Save haribote/10083798 to your computer and use it in GitHub Desktop.
Save haribote/10083798 to your computer and use it in GitHub Desktop.
;(function(window, undefined) {
var checkKey = '__WEB_STORAGE_CHECK__';
var isSupported = function(localOrSession) {
var _storage = window[localOrSession];
return _storage ? (function() {
try {
_storage.setItem(checkKey, 1);
_storage.getItem(checkKey);
_storage.removeItem(checkKey);
return true;
} catch (e) {
return false;
}
})() : false;
};
// 参照しやすいようにnavigatorオブジェクトを拡張する
navigator.isLocalStorageSupported = isSupported('localStorage');
navigator.isSessionStorageSupported = isSupported('sessionStorage');
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment