My understanding is that sessionStorage values should persist after page reloads, but also between pages in the same site as long as the same tab is used.
In a particular page I can set 2 sessionStorage values. They persist on reload and when I come back to that page from another.
I need to pick up these values on another page in the same site but I cannot. Am I missing something in the documentation that states this is not possible or am I doing something wrong?
I have tried localStorage also but same problem.
Given a scenario where my 2 sessionStorage values are set, I test for them with the following if statement, but it never gets to it. I have also tried logging each to the console but no luck.
Thanks.
if (Modernizr.sessionstorage) {
var
a = document.getElementById('aId'),
b = document.getElementById('bId'),
c = document.getElementById('cId'),
d = document.getElementById('dId'),
e = document.getElementById('eId'),
f = parseInt(b.value)*parseInt(d.value)+4;
var startValues = function (){
a.value = b.value;
c.value = d.value;
e.value = f;
};
var sessValues = function (){
b.value = sessionStorage.getItem('thingOne');
d.value = sessionStorage.getItem('thingTwo');
startValues();
};
if(sessionStorage.getItem('thingOne') !== null || sessionStorage.getItem('thingTwo') !== null){
sessValues();
}
else{
sessionStorage.setItem('thingOne', 1);
sessionStorage.setItem('thingTwo', 1);
startValues();
}
b.addEventListener('input', function () {
sessionStorage.setItem('thingOne', b.value);
a.value = b.value;
}, false);
d.addEventListener('input', function () {
sessionStorage.setItem('thingTwo', d.value);
c.value = d.value;
}, false);
}
Apologies. Completely caught up in testing locally. All fine on a server. Got prompt from here stackoverflow