window.addEventListener('load', function() { function updateOnlineStatus(event) { var condition = navigator.onLine ? "online" : "offline"; } window.addEventListener('online', updateOnlineStatus); window.addEventListener('offline', updateOnlineStatus); });