Created
April 12, 2012 23:14
-
-
Save furf/2371698 to your computer and use it in GitHub Desktop.
localStorage userData polyfill (old MSIE)
This file contains hidden or 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 (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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is jQuery used for? Seems like this could be library agnostic and it'd make no difference.