Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save singhmohancs/f742808ee03c23b2b34d1e8c6e5762f6 to your computer and use it in GitHub Desktop.
Save singhmohancs/f742808ee03c23b2b34d1e8c6e5762f6 to your computer and use it in GitHub Desktop.
localStorage Fallback
/* Checks if localStorage exists on the browser, if not, creates a JSONFallbackStorage object where all the data will be stored. Also creates the localStorage methods so you won't need to change anything on your script. Just remember to send the data on JSONFallbackStore to the server. */
(function(window, undefined){
if (typeof(localStorage) === undefined) {
JSONFallbackStore = {};
window.localStorage = {
getItem: function(key){
return JSONFallbackStore[key];
},
setItem: function(key, value){
JSONFallbackStore[key] = JSON.stringify(value);
},
removeItem: function(key){
delete JSONFallbackStore[key];
}
}
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment