-
-
Save jethrolarson/4535157 to your computer and use it in GitHub Desktop.
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
// Adds Support for localStorage to IE5-IE7 using userData | |
// <http://msdn.microsoft.com/en-us/library/ms531424(VS.85).aspx> | |
// See also <http://caniuse.com/#feat=namevalue-storage> | |
if(typeof window.localStorage === 'undefined') (function () { | |
var userdataKey = 'localStorage', | |
userdata = document.createElement('b'); | |
userdata.style.display = 'none'; | |
userdata.style.behavior = 'url("#default#userData")'; | |
document.body.appendChild(userdata); | |
userdata.load(userdataKey); | |
window.localStorage = { | |
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); | |
} | |
}; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This probably needs better error handling. This also doesn't make the localStorage api support object storage (JSON) which is a feature I love. This is just a simple polyfill so you have to make sure you're only storing strings. Also you have to use .getItem() and .setItem() or this polyfill wont work.