how to check if IE 5.5 is online

253 Views Asked by At

I'm trying to check if browser has internet connection with javascript but I encountered some problems on IE 5.5

<script>
function checkConnection(){
           if(navigator.onLine === false){
               //document.execCommand("Stop");
               alert("No internet connection.");
               document.execCommand("Stop");
}
</script>

and:

<input type="submit" value="GO" name="whereTo" onclick="checkConnection();"  />

It seems that IE 5.5 doesn't have navigator.onLine property, how can I check for connection for IE 5.5?

1

There are 1 best solutions below

0
MarcoL On

Why not trying to send an AJAX request? It won't check if you're strictly online, but it would tell you if you can reach something... Trying a couple of URLs might be enough...

function ajaxRequest(url) {
  var xmlhttp;
  if (window.XMLHttpRequest) {
    // code for IE 7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }  else {
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState !== 4 && xmlhttp.status !== 200) {
      alert("No internet connection.");
      document.execCommand("Stop");
    }
  }

  xmlhttp.open("GET",url, true);
  xmlhttp.send();
  return false;
}