Toufic Batache Toufic Batache - 4 months ago 11
Javascript Question

Stick a JavaScript outpout to a page

I have a code which adds 1 to 0 everytime I click on a button, but the problem is that I want the result to be displayed on the page forever. If the JavaScript outpouts 9 at the end, it should be there even if I reload the page. Can I do that ? Thanks.

Link to the code I have : jsfiddle.net/YdhTQ/

Answer

you can do this with local storage

localStorage.setItem("counter", variable);

and then you can retrieve this like

localStorage.getItem("counter");
Comments