Cookies
The best solution is to use cookies. A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is usually a small piece of data sent from a website and stored in a user's web browser while a user is browsing a website (from Wikipedia).
Using a cookie you can save the state and later read it and use it.
With jQuery it is very easy to use cookies.
To set:
$.cookie("var", "10");
To get:
$.cookie("var")
To delete:
$.cookie("var", null);
Local Storage
When you want to save localy great amount of data, you have another opportunity — to use local storage (since HTML5). You can do it directly using JavaScript or using one of available jQuery plugins.
for example, with totalStorage
:
var scores = new Array();
scores.push({'name':'A', points:10});
scores.push({'name':'B', points:20});
scores.push({'name':'C', points:0});
$.totalStorage('scores', scores);