I know this question has been discussed many times but there does not seem to be a universal working answer.
I have a web page that displays data which is continually updated and I need to work out how I can prevent the web page from refreshing if there is no internet connection.
I have tried many different approaches but without exception, went I disable my internet connection, browsers displays
Firefox: Server not found
Chrome: There is no internet connection
IE: You’re not connected to the internet
I have looked into various browser plug-ins but none of them work.
I have taken a look at navigator.onLine
but even using this browsers still display their own not connected pages. I have looked at using some sort of AJAX call without any success.
I do not need to worry about who is using which browser because this script is going to run on a known device configured to a known specification.
Is there a full proof method of preventing a page refresh until there is a connection?
loadDoc("example.com/comms_true.png", myFunction1);
function loadDoc(url, cFunction) {
var xhttp;
xhttp=new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
cFunction(this);
setTimeout(function() {
location.reload();
}, 30000);
} else {
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function myFunction1(xhttp) {
setTimeout, 30000;
}