DEV Community

Discussion on: Reload page after a set interval ?

Collapse
 
coolprofessor profile image
coolprofessor

How did you set up the setInterval?

Collapse
 
offcorner profile image
OffCorner Developer

what exactly do you mean?
if the page is loaded, we check if there is an entry in localStorage saying "reloadActive":true. if that is the case, set a timeout to reload the page after 5 seconds (and then the website loads again and checks again) => so we don't use setInterval to reload our website, it is just a timeout that reloads the website and starts again.

if the localstorage tag "reloadActive" is set to false, we only increase the counter every second.

once the start counter button is pressed, we set the flag in the localStorage and set a timeout for 5 seconds.

once the stop button is pressed, we clear the flag in localStorage and remove the timeout that would reload the page