Skip to content

Instantly share code, notes, and snippets.

@basecss
Created January 26, 2014 12:55
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 basecss/8632273 to your computer and use it in GitHub Desktop.
Save basecss/8632273 to your computer and use it in GitHub Desktop.
localStorage
function localStorageSupport() {
try {
return ('localStorage' in window && window['localStorage'] !== null)
} catch(e) {
console.log(e.stack);
}
return false;
}
function addData(key, data) {
if(localStorageSupport()) {
localStorage.setItem(key, data);
}
}
function getData(key) {
if(localStorageSupport()){
return localStorage.getItem(key);
}
}
function removeData(key) {
if(localStorageSupport()) {
localStorage.removeItem(key);
}
}
function clearData() {
localStorage.clear();
}
function getLength() {
return localStorage.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment