title: check internet connection with phonegap
body: <p>I am seeing a few different options to check internet connection with phonegap. There is <code>document.addEventListener("online", onOnline, false);</code> and there is also <code>navigator.network.connection.type</code>... but I am not sure which one is best practice. I would also like to be able to prevent the bad case where the phone is connected to a wifi network but has no internet connection.</p>
  
  <pre><code>$(document).on('pagecreate','#explanation-short', function(){
       if ( isPhoneGap() ) {
      if (checkConnection() == "none" ) {
          connectionStatus = 'offline'; 
      } else {
          connectionStatus = 'online';
      }
      function checkConnection() {
          var networkState = navigator.network.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.NONE]     = 'No network connection';
          //console.log('Connection : ' + Connection);
          //console.log('Connection type: ' + states[networkState]);
          return networkState;
      }
  } else {
      connectionStatus = navigator.onLine ? 'online' : 'offline';
  }
      console.log("connectionStatus : "+connectionStatus);
  });
  </code></pre>
  
  <p>For example, this code works if the phone is connected to the wifi, but we are not sure the internet is actually available.</p>
  
  <p>What are the best practices with phonegap 3.3+ and Jquery mobile 1.4 ?</p>