Created
December 3, 2010 13:08
-
-
Save remy/726930 to your computer and use it in GitHub Desktop.
Quick sessionStorage polyfill
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
if (!sessionStorage && JSON) { | |
sessionStorage = (function () { | |
var data = window.name ? JSON.parse(window.name) : {}; | |
return { | |
clear: function () { | |
data = {}; | |
window.name = ''; | |
}, | |
getItem: function (key) { | |
return data[key] === undefined ? null : data[key]; | |
}, | |
removeItem: function (key) { | |
delete data[key]; | |
window.name = JSON.stringify(data); | |
}, | |
setItem: function (key, value) { | |
data[key] = value; | |
window.name = JSON.stringify(data); | |
} | |
}; | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment