Reputation: 99
So I am working on a shopping cart that does not use cookies.
In my first page (the store) I define several variables such as item quantities,item names,etc.
In my second page (the checkout) I need to access the variables from the first page and display them to the user. How can I do so?
Upvotes: -1
Views: 47
Reputation: 24360
There is no way to do it in JavaScript without using the environment outside of the language itself. All variables will lose their values when the page reloads.
There are plenty of possible solutions though. Which one is best depends on your constraints:
Edit: recommendation
The easiest of the above would be to go with the local storage solution, as described by murli2308 below. Write a variable with localStorage.setItem("myVarName", "myVarValue")
on the first page and read it with localStorage.getItem("myVarName")
on the second page.
Upvotes: 4
Reputation: 2994
You can use local storage of HTML5 to store the data.
localStorage.setItem("key", "value");
Also if you want to use session storage you can use it
sessionStorage.key = valuetoupdate;
Upvotes: 0