title: How to detect device's internet connection in jQuery Mobile
body: <p>I am creating this simple mobile web page for a survey using HTML5, CSS3, jQuery Mobile, jQuery UI, ASP.NET, C# and some jQuery Plugins. One of the requirements is to show a pop-up/ dialog (either javascript alert or a jQuery mobile dialog or much better if it's a jQuery UI dialog) that will notify user whenever there is no internet connection the device (specifically Android). Currently I have this code:</p>
  
  <pre><code>&lt;link rel="stylesheet" href="../Scripts/jqueryui/jquery-ui.css" type="text/css" media="all" /&gt;
  &lt;link rel="stylesheet" href="../Scripts/jquery.mobile-1.1.0.css" /&gt;
  &lt;script src="../Scripts/jquery-1.7.1.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="../Scripts/jquery.mobile-1.1.0.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="../Scripts/jqueryui/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="../Scripts/jqueryui/jquery-ui.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="../Scripts/jquery.validate.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
      var online = window.navigator.onLine;
      if (!online) {
          alert('Please check your internet connection and try again.');
      }
      function checkInternet() {
          var online = window.navigator.onLine;
          if (!online) {
              alert('Please check your internet connection and try again.');
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>then I put the JavaScript function on the form's onsubmit event:</p>
  
  <pre><code>&lt;form id="frmSurvey" runat="server" class="validate" onsubmit="checkInternet()"&gt;
  </code></pre>
  
  <p>It's working when I view it on a desktop/ PC browser but doesn't work on mobile at all. The jQuery Mobile error loading page.</p>
  
  <p>Since, this ain't the requirment I tweaked the jQuery Mobile file commented out the error loading page message part and it doesn't appear anymore. I've tried Google-ing a lot searching for any related topics but not found any.</p>
  
  <p>I'm really having a hard time making this possible. Please help me guys! </p>
  
  <p>Thanks in advance!</p>