HTML and CSS Reference
In-Depth Information
data = {};
window.top.name = '';
},
getItem: function (key) {
return data[key] || null;
},
key: function (i) {
// not perfect, but works
var ctr = 0;
for (var k in data) {
if (ctr == i) return k
else ctr++;
}
},
removeItem: function (key) {
delete data[key];
window.top.name = JSON.stringify(data);
},
setItem: function (key, value) {
data[key] = value+''; // forces the value to a
¬ string
window.top.name = JSON.stringify(data);
}
};
})();
}
The problem with implementing sessionStorage manually (as
shown in the previous code listing) is that you wouldn't be able
to write sessionStorage.twitter = '@rem' . Although techni-
cally, the code would work, it wouldn't be registered in our stor-
age object properly and sessionStorage.getItem('twitter')
wouldn't yield a result.
With this in mind, and depending on what browsers you are tar-
geting (that is, whether you would need to provide a manual fall-
back to storage), you may want to ensure you agree within your
development team whether you use getItem and setItem .
 
Search WWH ::




Custom Search