1window.addEventListener('load', function() {
2 var status = document.getElementById("status");
3 var log = document.getElementById("log");
4
5 function updateOnlineStatus(event) {
6 var condition = navigator.onLine ? "online" : "offline";
7
8 status.className = condition;
9 status.innerHTML = condition.toUpperCase();
10
11 log.insertAdjacentHTML("beforeend", "Event: " + event.type + "; Status: " + condition);
12 }
13
14 window.addEventListener('online', updateOnlineStatus);
15 window.addEventListener('offline', updateOnlineStatus);
16});