-
-
Save singhmohancs/f742808ee03c23b2b34d1e8c6e5762f6 to your computer and use it in GitHub Desktop.
localStorage Fallback
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
/* 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