title: How to check if site is online with JavaScript? Plus tips on how to make the rest of this function work better
body: <p>I need to check if a website is online and to get ping time.</p>
  
  <p>I already have a rough ping time (close enough). But I still need to check if the site is online and make the function run five times, and get the lowest ping value (in order to get it more accurate).</p>
  
  <p>My code so far:</p>
  
  <pre><code>&lt;script&gt;
    function initPingTest(siteUrl){
      pingTester();
      function pingTester(){
        document.getElementById('site').innerHTML = '&lt;center&gt;' + siteUrl + '&lt;/center&gt;';
        document.getElementById('pingT').innerHTML = '&lt;center&gt; testing.. &lt;/center&gt;';
      var startTime=new Date();
      window.startTime=startTime.getTime();
      var imgSrc=siteUrl+ '?cacheBuster='+Math.random();
      var iFrame=document.getElementById('myPingTest');
      iFrame.onload=pingTime;
      iFrame.src=imgSrc;
      function pingTime() {
        var endTime=new Date();
        var pingResult = (endTime.getTime()-window.startTime);
        if(pingResult&lt;hidden.hidden.value){
          document.getElementById('pingT').innerHTML = '&lt;center&gt;' + pingResult + '&lt;/center&gt;';
          hidden.hidden.value=pingResult;
        }else{document.getElementById('pingT').innerHTML = '&lt;center&gt;' + hidden.hidden.value + '&lt;/center&gt;';}
        } 
      } 
    }
  &lt;/script&gt;
  
  &lt;IFRAME style="display:none;" id=myPingTest&gt;&lt;/IFRAME&gt;
  &lt;FORM NAME="hidden" STYLE="display:none"&gt;&lt;INPUT TYPE="text" NAME="hidden" value="100000"&gt;&lt;/form&gt;
  &lt;br&gt;
  &lt;FORM method="get" NAME="ping" action="javascript:initPingTest(ping.url.value);"&gt;&lt;font&gt;Enter site adress(ie.www.yahoo.com)&lt;br&gt;http://&lt;/font&gt;
    &lt;INPUT TYPE="text" NAME="url" size="18"&gt;&lt;input type="submit" value="Ping"/&gt;&lt;/form&gt;
    &lt;br&gt;
    &lt;table cellspacing=5px&gt;
      &lt;tr&gt;&lt;th&gt;
        Url:
      &lt;/th&gt;&lt;th&gt;
        Ping Time (miliseconds)
      &lt;/th&gt;&lt;/tr&gt;
      &lt;tr&gt;&lt;td&gt;
        &lt;label id=site&gt;&lt;center&gt; - &lt;/center&gt;&lt;/label&gt;
      &lt;/td&gt;&lt;td&gt;
        &lt;label id=pingT&gt;&lt;center&gt; - &lt;/center&gt;&lt;/lable&gt;
      &lt;/td&gt;&lt;/tr&gt;
    &lt;/table&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>