title: What is the best way to check if the device has Internet access?
body: <p>I want to check if the device has <strong>internet access</strong>. From the official cordova documentation:</p>
  
  <p>This code, is only to get the <code>connection type</code></p>
  
  <pre><code>function checkConnection() {
      var networkState = navigator.connection.type;
  
      var states = {};
      states[Connection.UNKNOWN]  = 'Unknown connection';
      states[Connection.ETHERNET] = 'Ethernet connection';
      states[Connection.WIFI]     = 'WiFi connection';
      states[Connection.CELL_2G]  = 'Cell 2G connection';
      states[Connection.CELL_3G]  = 'Cell 3G connection';
      states[Connection.CELL_4G]  = 'Cell 4G connection';
      states[Connection.CELL]     = 'Cell generic connection';
      states[Connection.NONE]     = 'No network connection';
  
      alert('Connection type: ' + states[networkState]);
  }
  
  checkConnection();
  </code></pre>
  
  <p>But how can I check if the device really have internet access? That is, because it may be that the device is connected to a router using a WiFi connection type, but that it has no access to internet but only local access. In this case the <code>checkConnection();</code> will return: <code>WiFi connection</code>.</p>
  
  <p>Or that is connected to a 3G network phone operator, but the user does not have sufficient credits for the internet. In this case the <code>checkConnection();</code> will return: <code>Cell 3G connection</code></p>
  
  <p>But in both cases the user have not a real internet access eventhough if connected.</p>
  
  <p>The only thing that I think is to ping google or another server to check if there really has internet access, in the case of <code>states[networkState] != No network connection</code></p>
  
  <p>Or do you think <code>navigator.onLine</code> can run on all devices (Android, iOS, BlackBery 10?</p>
  
  <p>I hope I have expressed well, my English really sucks.</p>