I have some trivial code like the following:
var timer_ends = some_ts; var timer = setInterval(function() { time_diff = /* some calculation */ if ( time_diff <= 0 ) { clearInterval(timer) // Want to location.reload(true) here but it would recursively run return; } }, 1000); Once the timer hits 0 or below, I want to
- clearInterval(timer)
- I want to refresh the page
The problem is, if I refresh the page, the timer will just restart and we'll recursively keep refreshing. What is the best way to execute the location.reload(true) once and only once the first time time_diff hits 0. Also, if the user is coming to the page for the first time and it's already at 0 it shouldn't refresh.