forked from PixelsCommander/OnlineJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
64 lines (63 loc) · 2.54 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./src/online.js"></script>
<title>OnlineJS demo page</title>
</head>
<body style="font-family: Arial">
<div style="float:left; position: relative;">
<img id="red_light" src="./img/traffic_red.png" style="opacity:0;">
<img id="green_light" src="./img/traffic_green.png" style="position: absolute; left: 0px; top: 0px;">
</div>
<div style="float:left; margin-left: 40px;">
<h1 id="online_title">Checking online presence</h1>
<p>
Switch internet connection on / off or plug in / out network cord to test Online JS
</p>
<p>
Online JS developed to provide reliable and easy way to check internet connection status and work as fast as possible.
</p>
<p>
Optimisations implemented:
</p>
<ul>
<li>Checks status in background mode</li>
<li>Requests only headers to minimize traffic</li>
<li>Listens for window.online/offline events and verifies them</li>
</ul>
<h2>
Usage
</h2>
<p>
Include this library into your project and just check is <b>window.onLine === true</b>
</p>
<p>
Define <b>window.onLineHandler</b> or <b>window.offLineHandler</b> functions to handle status changes.
</p>
<h2>
Links
</h2>
<p>
<a href="https://github.com/PixelsCommander/OnlineJS">OnlineJS on Github<a/>
</p>
<p>
<a href="https://github.com/PixelsCommander/OnlineJS/archive/master.zip">Download ZIP<a/>
</p>
</div>
<script>
var greenLight = document.getElementById('green_light');
var redLight = document.getElementById('red_light');
window.onLineHandler = function(){
greenLight.style.opacity = 1;
redLight.style.opacity = 0;
document.getElementById('online_title').innerHTML = 'YOU ARE ONLINE';
};
window.offLineHandler = function(){
greenLight.style.opacity = 0;
redLight.style.opacity = 1;
document.getElementById('online_title').innerHTML = 'YOU ARE OFFLINE';
};
</script>
</body>
</html>