hi, this function test if your server is joignable or not :

<div id="serverStatus">SERVER</div>
<div id="pings">TIME</div>
<SCRIPT>
  var numPings = 0;
  var request = google.gears.factory.create('beta.httprequest');
  var TIME_BETWEEN_PINGS = 3*1000;
  var PING_TIMEOUT_SECONDS = 1*1000;
  function pingSuccess() {
    if(request.responseText != "" && request.responseText.indexOf("404 Page
not found") == -1){
      document.getElementById('serverStatus').innerHTML = "[Server
Accessible]";
    } else {
      document.getElementById('serverStatus').innerHTML = "[Server
Inaccessible]";
    }
  }
 function isServerAvailable() {
   var resource_to_test = "http://localhost:8080/ZZenfance/usager.jsp";;
    resource_to_test + "?q=" + Math.floor(Math.random() * 100000);
    request.open('Get',resource_to_test);
    window.setTimeout("pingSuccess()",PING_TIMEOUT_SECONDS);
    request.onreadystatechange = function() {
      if (request.readyState == 4) {
        numPings++;
        document.getElementById('pings').innerHTML = "Number of pings: " +
numPings;
      }
    };
    request.send();
    window.setTimeout("isServerAvailable()",TIME_BETWEEN_PINGS);
  }
  isServerAvailable();
</SCRIPT>

And this function show that are you connected or not :

// Test if the browser is connected to the Internet
function online(){
     return navigator.onLine;
}

Reply via email to