Reading the first paragraph I already thought: localStorage for the rescue! But then on the second paragraph you say you already tried it.
What went wrong with localStorage? Can you provide the code you used to interact with it?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have some dynamic JS data on the page. When the user goes to a new page I need that data to be automatically saved for use when they return. When they return, the data must be available for increment. So, for example: I have counted 10 students having arrived. I am not doing page refreshes, so I am counting using JS. Great. My user leaves the page, but comes back later. They need to continue adding student to the original 10. Without some auto storage, the original data is lost.
I have tried using localStorage without success. I have also tried using onbeforeunload, but that does not give an autosave capability. This all might sound trivial, but it is deceiving.
Any suggestions? Many thanks !
@vincej thanks!
When this page loads you could hydrate the count variable from localStorage:
var count = Number(localStorage.getItem('Count') || 0);
// ...
Just don't forget to remove or to reset the Count from localStorage when they finish working with the data.
Please or to participate in this conversation.