MCPcopy
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / isOnline

Function isOnline

assets/js/DetectInternetconnection.js:6–22  ·  view source on GitHub ↗
(no, yes)

Source from the content-addressed store, hash-verified

4const wifiIcon = card.querySelector('.icon');
5
6function isOnline(no, yes) {
7 var xhr = XMLHttpRequest
8 ? new XMLHttpRequest()
9 : new ActiveXObject('Microsoft.XMLHttp');
10 xhr.onload = function () {
11 if (yes instanceof Function) {
12 yes();
13 }
14 };
15 xhr.onerror = function () {
16 if (no instanceof Function) {
17 no();
18 }
19 };
20 xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts.php', true);
21 xhr.send();
22}
23
24isOnline(
25 function () {

Callers 1

Calls 1

openMethod · 0.80

Tested by

no test coverage detected