My application work tries to store some data on my local storage which works fine when i am not opening any new tab or window, but when i open a new tab, my array loses all its previous stored data and stores only the current data. Please suggest what i am doing wrong here.
my code is something like this:
getCurrReqIdList = [];
localStorage.setItem('getCurrReqIdList', JSON.stringify(getCurrReqIdList));
var retrievedData = localStorage.getItem('getCurrReqIdList');
var getFinalReqIdList = JSON.parse(retrievedData);
if(getFinalReqIdList.length > maxCurrentConnectionLength) {
console.log('Hello');
getFinalReqIdList.shift();
getCurrReqIdList.shift();
localStorage.setItem('getCurrReqIdList',JSON.stringify(getFinalReqIdList));
}
According to: This
you can't share data between multiple tabs using sessionStorage, because a new page is a new session.
You need to replace
setStorageType('sessionStorage')
by
setStorageType('localStorage') // which is default
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With