Skip to content

Instantly share code, notes, and snippets.

@JohannesFischer
Last active February 19, 2016 08:24
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 JohannesFischer/bf7b6831c8a748b3fbdb to your computer and use it in GitHub Desktop.
Save JohannesFischer/bf7b6831c8a748b3fbdb to your computer and use it in GitHub Desktop.
localStorage polyfill (non persistent)
try {
window.localStorage.setItem('testKey', '1');
window.localStorage.removeItem('testKey');
}
catch (error) {
window.localStorage = {
_data: {},
setItem: function(id, val) { return this._data[id] = String(val); },
getItem: function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
removeItem: function(id) { return delete this._data[id]; },
clear: function() { return this._data = {}; }
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment