Toufic Batache Toufic Batache - 1 year ago 74
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 :

Answer Source

you can do this with local storage

localStorage.setItem("counter", variable);

and then you can retrieve this like