Skip to content

Instantly share code, notes, and snippets.

@N-Porsh
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save N-Porsh/0d56dd4d52747d7bd86b to your computer and use it in GitHub Desktop.
Save N-Porsh/0d56dd4d52747d7bd86b to your computer and use it in GitHub Desktop.
JavaScript: localStorage - cookies replacement
// 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