Last active
August 29, 2015 14:22
-
-
Save N-Porsh/0d56dd4d52747d7bd86b to your computer and use it in GitHub Desktop.
JavaScript: localStorage - cookies replacement
This file contains 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
// thin wrapper around local-storage to avoid | |
// errors if the browser does not support it. | |
var globalVar.localStorage = { | |
set: function(key, value) { | |
if (!swarm.localStorage.canStore()) { | |
return null; | |
} | |
return window.localStorage.setItem(key, value); | |
}, | |
get: function(key) { | |
if (!swarm.localStorage.canStore()) { | |
return null; | |
} | |
return window.localStorage.getItem(key); | |
}, | |
canStore: function() { | |
try { | |
return window.localStorage !== undefined && window.localStorage !== null; | |
} catch (e) { | |
return false; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment