I have a webpage that displays ads. The page refreshes based on a users input of lets say 60 minutes for example. So if there are new ads to be displayed after the hour is up, the page will refresh itself (using JavaScript) and show the new ads.
<body oncontextmenu="return false;" onload="JavaScript:timedRefresh(<?php echo $tvout_refresh; ?>);">
$tvout_refresh
is 60 mins.
Now, I've run into a slight problem, if the webpage goes offline, the page will redirect to a browser's offline page (the page that says that it can't access the website) after the timer runs out (60 mins, refreshes the page).
I've seen this piece of code after a bit of search, Allowing me to detect if the browser is online or offline.
if (navigator.onLine) {
alert('online')
} else {
alert('offline');
}
and
window.addEventListener("offline", function(e) {
alert("offline");
}, false);
window.addEventListener("online", function(e) {
alert("online");
}, false);
Now, regardless if the browser is offline or online the browser will only detect it's offline when my refresh script timer runs out and refreshes the page. Is there a way to insert a script that determines the browser is offline, skips the refresh, and resets the timer and tries again in 60 more minutes, avoiding the browser offline page?
timedRefresh
is defined as follows:
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);", timeoutPeriod);
}