yanknudtskov
7/6/2017 - 1:00 PM

JavaScript to check online connectivity

JavaScript to check online connectivity

<script>
(function () {
  // var status = document.getElementById('status'); // Der kunne laves et HTML element til dette
  // status.className = navigator.onLine ? 'online' : 'offline';
  window.addEventListener('online', function () {
    // status.className = 'online';
    // status.innerHTML = 'ONLINE'; 
  }, false);

  window.addEventListener('offline', function () {
    // status.className = 'offline';
    // status.innerHTML = 'OFFLINE'; 
    alert('You are offline');
  }, false);
})();
</script>