0

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!

2
  • 2
    Have you tried something? Source code? Commented Apr 27, 2015 at 7:35
  • I tried cookies but its too many values and it gets very messy, its my last solution Commented Apr 27, 2015 at 7:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

what about sessionStorage, any experience with that?
Actually sessionStorage persist for session only and if session ends or tab closed it will get destroyed
I want that.. now my problem is to store undefined arrays (depending on how many divs selected and their data) and then load them.
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.
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
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.