title: Quickest way to check internet connectivity in JS
body: <p>I have this code in a html file that checks for connectivity, but the problem here is that it takes about 10 seconds to throw the alert message box to indicate the connection is lost. I want to know if there's a much faster way to inform the user that the connection is lost without having to wait.
  Strictly JS thanks...</p>
  
  <p>JS code:</p>
  
  <pre><code>&lt;script language="JavaScript"&gt;
  function SubmitButton()
  {
      if(navigator.onLine)
      {
              document.getElementById('SubmitBtn').style.visibility='visible';
      }
      else
      {
          document.getElementById('SubmitBtn').style.visibility='hidden';
      }
  }
  function Online() 
  { 
      var status=false;
      status= navigator.onLine;
      if(status!= true)
      {
          alert('Network connectivity is lost, please try again later');
      }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Calling it in html file here:</p>
  
  <pre><code>&lt;INPUT name="ccMCA1input" type="checkbox" onclick="ccMCA1.ccEvaluate(),Online()" value=False&gt;
  </code></pre>