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


my application work tries store data on local storage works fine when not opening new tab or window, when open new tab, array loses previous stored data , stores current data. please suggest doing wrong here.

my code 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));            } 

the post bit confusing, bet have lines

getcurrreqidlist = []; localstorage.setitem('getcurrreqidlist', json.stringify(getcurrreqidlist)); 

running every time load page, initializing store. when open new tab, loads page , override local storage value empty array.

you page should run like:

getcurrreqidlist = localstorage.getitem('getcurrreqidlist'); if(getcurrreqidlist) {      getcurrreqidlist = json.parse(getcurrreqidlist); } else {     getcurrreqidlist = [];     localstorage.setitem('getcurrreqidlist', json.stringify(getcurrreqidlist)); } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -