Reputation: 31
I have a site in production environment that reloads automatically every 3 mins. However, sometimes it gets stuck and does not update.
So I am looking for a small bit of javascript which will check the time since last page reload and if it exceeds 4 mins since last refresh then it will show me a alert that the page has not been updated since last 4 minutes or so.
Can I have a counter value which resets when page is reloaded and when if it exceeds a certain value say after 3 mins it gives a alert popup.
Can this be done?
Upvotes: 1
Views: 236
Reputation: 31
The final code for someone else if they require. Thanks for maximus help
<script>
function reloadCheck() {
setInterval(function(){alert("Please Reload Page")},10000);
}
</script>
<body onload="reloadCheck()">
Checking page Reload
</body>
Upvotes: 1
Reputation: 105439
Your javascript code starts executing once a page is loaded. Write some function that will be executed once the page is loaded and set timer to 4 minutes which will generate the notification. If the page reloads than the timer won't reach it's time and no notification will be generated.
Read about timer here
Upvotes: 1