jquery - Localstorage incrementing array to 20 -
my setup have home, about, , contact page. there nothing on pages each of 3 links on each of 3 pages , button in middle of each page.
my goal url session button clicked in, pushed array can hold 20 links. can same page multiple times, essentially, button can clicked 20 times(i'll figure out how catch if it's done in same session later).
my issue
i'm having trouble passing both url current session , building array current url passed into, same building array. here i'm working with:
var seshstore = [], localstore = [], currenturl = window.location.href, newlink = $('<a class="new-link" href="' + currenturl + '">new link</a>'); $(document).ready(function(){ // push local store last sesh var storedlinks = json.parse(localstorage.getitem("localstore")); var restoredlocalstore = json.parse(localstorage.getitem("restoredlocalstore")); localstore.push(storedlinks); localstore.push(restoredlocalstore); (var = 0; <= 20; i++) { console.log(localstore[i]); } localstorage.setitem("restoredlocalstore", json.stringify(localstore)); $('.link-button').click(function(){ $(newlink).appendto('body'); var reinitlink = currenturl; // push current url sesh storage , temp storage local until next sesh // seshstore.push(reinitlink); // localstore.push(reinitlink); localstorage.setitem("localstore", json.stringify(window.location.href)); // console.log(seshstore); }); // localstorage.clear(); });
i think have no initialization localstorage "localstore".
currently set variable localstore array.
try set like:
localstorage.localstore = ""; localstorage supports strings.
use json.stringify() [as used] , json.parse() [for getting values].
// setting values var example = ["link1", "link2", "link3"]; localstorage.setitem("names", json.stringify(names)); // getting values var localstore = json.parse(localstorage.getitem("localstore")); kindly modify code wish.
Comments
Post a Comment