Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick sessionStorage polyfill
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