Skip to content

Instantly share code, notes, and snippets.

@furf
Created April 12, 2012 23:14
Show Gist options
  • Select an option

  • Save furf/2371698 to your computer and use it in GitHub Desktop.

Select an option

Save furf/2371698 to your computer and use it in GitHub Desktop.
localStorage userData polyfill (old MSIE)
(function (window, document, $) {
$.support.localStorage = 'localStorage' in window && window['localStorage'] !== null;
$.storage = $.support.localStorage ? window.localStorage : (function () {
var userdataKey = 'localStorage',
userdata = document.createElement('b');
userdata.style.display = 'none';
userdata.style.behavior = 'url("#default#userData")';
// userdata.addBehavior('#default#userdata');
document.body.appendChild(userdata);
userdata.load(userdataKey);
return {
setItem: function (key, val) {
userdata.setAttribute(key, val);
userdata.save(userdataKey);
},
removeItem: function (key) {
userdata.removeAttribute(key);
userdata.save(userdataKey);
},
getItem: function (key) {
return userdata.getAttribute(key);
}
}
})();
})(this, document, jQuery);
@jethrolarson
Copy link

What is jQuery used for? Seems like this could be library agnostic and it'd make no difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment