A simpler solution would be to use sessionStorage , in this case:
var myVariable = true; sessionStorage['myvariable'] = myVariable; myVariable = sessionStorage['myvariable'];
However, keep in mind that sessionStorage saves everything as a string, so when working with arrays / objects, you can use JSON to store them:
var myVariable = {a:[1,2,3,4], b:"some text"}; sessionStorage['myvariable'] = JSON.stringify(myVariable); myVariable = JSON.parse(sessionStorage['myvariable']);
A page session lasts as long as the browser is open and survives reloading and restoring the page. Opening a page in a new tab or window will start a new session.
So, when you close the page / tab, the data is lost.
Cerbrus Jan 07 '13 at 13:12 2013-01-07 13:12
source share