I need to store some dynamic variables in a Json file (i was told this would work) to be able to load them in multiple pages. Per example a customer should be able to select one thing in one page (a highlighted div) and then go to another page, select some items there and be able to go pack to the other page and that div is still selected. (Variables remembered) Now i tried to google and search here but found nothing matching my description. Please help me!
-
2Have you tried something? Source code?Zee– Zee2015-04-27 07:35:21 +00:00Commented Apr 27, 2015 at 7:35
-
I tried cookies but its too many values and it gets very messy, its my last solutionPlainawesomeweb– Plainawesomeweb2015-04-27 07:49:33 +00:00Commented Apr 27, 2015 at 7:49
Add a comment
|
1 Answer
Try using localstorage, store selected values by user in localstorage and check this at page ready or load if it exists in loacalstorage show that value or div with highlight as per your functionality and if localstorage doesn't had a value then consider it as first time user come to this page. but be careful using localstorage as you have to clear it when you done with it, it may cause memory leakage problem.
6 Comments
Plainawesomeweb
what about sessionStorage, any experience with that?
syms
Actually sessionStorage persist for session only and if session ends or tab closed it will get destroyed
Plainawesomeweb
I want that.. now my problem is to store undefined arrays (depending on how many divs selected and their data) and then load them.
Plainawesomeweb
I need something that parses through all divs with a specific class, if the data matches the data once clicked/toggled I want it to be selected (set a specific class to div) like this algorithm: If click div -> toggle class 'selected' -> If div has class 'selected' -> add divs data to sessionStorage -> elseIf div does not have class 'selected' -> remove divs data from sessionStorage. I have many divs with the same class so I need some kind of foreach array to store.. hehe I'm terrible at explaining but i hope you understand.
syms
actually you can not store direct array or object in session storage, you have to do this all by creating another object and then convert it to string and store in sessionStorage, for this you can replace whole object from sessionStorage. and when you want to get back from storage just convert it to object run your logic modify object and replace in sessionStorage
|