Skip to content

Instantly share code, notes, and snippets.

@remy
Created December 3, 2010 13:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save remy/726930 to your computer and use it in GitHub Desktop.
Save remy/726930 to your computer and use it in GitHub Desktop.
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