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:
- Store them on the server (using ajax or similar).
- Store them in local storage
- Store them in a cookie
- Avoid reloading the page (e.g. single page approach)
- Put them in the URL and have the new page parse them from there.
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.