Check internet connection using JavaScript

Sometimes you need to check device have internet connection or not.

This can be done by simple JavaScript function

var connectionMessage = "Your device have internet connection.";
var noConnectionMessage = "Ohh! It seems that your device dont have internet connection.";
window.onload = checkInternetConnection;
function checkInternetConnection() {
  var isOnLine = navigator.onLine;
  if (isOnLine) {
    alert(connectionMessage);
  } else {
    alert(noConnectionMessage);
  }
}

Enjoy JavaScript…

Published by

Mandar Badve

Microsoft web, cloud, mobile developer

Leave a Reply

Your email address will not be published. Required fields are marked *