'Endless page refresh [duplicate]
I wanted the page to refresh after 1 second and that's it, but after 1 second I get an infinite page refresh. How to fix endless page refresh?
function sayHi() {
document.location.reload();
return false;
}
setTimeout(sayHi, 1000);
<div class="timer">
Infinity refresh =(
</div>
Solution 1:[1]
When you reload the page, it's going to run the setTimeout again. You can use sessionStorage to make sure you refresh once per session.
if(!sessionStorage.getItem('refreshed')) {
sessionStorage.setItem('refreshed', true);
setTimeout(sayHi, 1000);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mystical |
