Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opening a new tab loses the arraylist in local storage javascript stack overflow

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));           
}
like image 859
user2067736 Avatar asked May 10 '26 15:05

user2067736


1 Answers

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
like image 85
Morteza QorbanAlizade Avatar answered May 12 '26 04:05

Morteza QorbanAlizade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!