I play with the implementation of the ping tool JavaScript server based on the accepted answer asked on this question: Is it possible to execute a ping server with Javascript? . This, in fact, works if you assume that the pinged server is down, if after n milliseconds no response has been received.
It's great, and it's a pretty cool way to do it, however there are two pretty big pitfalls:
- Not all servers respond within the allotted time.
- Sometimes before the timeout timer ends, an error is thrown
ERR_CONNECTION_TIMED_OUT.
Both of these things cause incorrect results. The first assumes that the server is offline when it is probably online and responds slowly, and the latter offers the server on the network when it is (probably) offline.
In an ideal world, this code would record what type of error was thrown and process it accordingly. In the end, if the error was caused by a 404 Not Found error, it counterintuitively means that the server is connected to the network and responded.
If we register an image error event, the only thing we see around the error is:
Event {
...
type: "error"
}
There is no message or anything hinting that an error has occurred, and 404 errors ERR_CONNECTION_TIMED_OUTgive identical information.
, ERR_CONNECTION_TIMED_OUT, Chrome JavaScript, , ?
Update
Trante JSFiddle ( , ) 30000 , 1500 :
this.timer = setTimeout(function () {
if (_that.inUse) {
_that.inUse = false;
_that.callback('timeout');
}
}, 30000);
'unknown' , :

Chrome :
: net::ERR_NAME_NOT_RESOLVED
Image onerror , , , , 1. 'unknown' 2. . ERR_NAME_NOT_RESOLVED , Chrome, .
2
- , , , . , , type: "error" - , .