I have a web page (classic asp) with a link to a local IP address, as follows:
JavaScript
x
2
1
<a href="http://192.168.1.89">Link</a>
2
If the local IP address is unavailable the web browser eventually times out and displays its own error message.
What I want to do is: catch the timeout before the browser displays its default error page and display an error on the same web page, next to the “Link”.
e.g. <a href="http://192.168.1.89">Well Pump</a><div id="timeoutmsg">offline</div>
I am guessing I need some JavaScript and the timeout function, but I don’t know where to begin.
Advertisement
Answer
Found this awesome workaround using pure javascript, no JScript, no ajax, no external libraries.
Works at treat:
Just need to upload a “test.gif” file to the local site(s).
JavaScript
1
11
11
1
var url = 'http://192.168.1.89';
2
var img = new Image();
3
img.src = url + '/test.gif';
4
img.onload = function() {
5
document.getElementById("msg").innerHTML = "";
6
window.location.href = url;
7
}
8
img.onerror = function() {
9
document.getElementById("msg").innerHTML = "offline";
10
}
11