Created
January 26, 2014 12:55
-
-
Save basecss/8632273 to your computer and use it in GitHub Desktop.
localStorage
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
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