I've been looking for a solution that will reload the a page at a specified interval, but only if the server from which that page comes from can deliver the page. Network problems, server problems, etc. should prevent the page from trying to reload. I'm a little surprised that there isn't more of a ready solution, since it seems like this would be the preferred behavior most of the time, instead of loading a blank page with an error message.
I tried to add on to a solution already on stackoverflow:
Javascript: Check if server is online?
but I while it does reload periodically, it doesn't stop trying to reload if the network isn't working (I turn WiFi off to simulate this). I did not try to simulate a server problem.
Here is my non-working version of a periodic reload:
function reloadpage() {
setTimeout(checkServerStatus, 60000);
}
function checkServerStatus() {
var img = document.body.appendChild(document.createElement("img"));
img.onload = function() {
location.reload(true);
};
img.src = "http://some/image.jpg";
}