-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
19 lines (19 loc) · 1020 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
try {
window.addEventListener('load', function() {
function checkStatus() {
//assign either .online or .offline className
//you can use an if statement to check
//once assigned it will change the color to either green or red
window.document.getElementById('status').className = navigator.onLine ? 'online' : 'offline';
//display the current connection status
//you can use an if statement or Conditional (ternary) Operator
window.document.getElementById('status').innerHTML = 'You Are : ' + window.document.getElementById('status').className;
}
//detect whether browser is online
//invoke the function to do the operation
window.addEventListener('online', checkStatus);
//detect whether browser is offline
//invoke the function to do the operation
window.addEventListener('offline', checkStatus);
});
} catch (error) { window.console.log(error) }