简体   繁体   English

如何检查IE 5.5是否在线

[英]how to check if IE 5.5 is online

I'm trying to check if browser has internet connection with javascript but I encountered some problems on IE 5.5 我正在尝试检查浏览器是否与javascript的互联网连接,但我在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? 看来IE 5.5没有navigator.onLine属性,我如何检查IE 5.5的连接?

Why not trying to send an AJAX request? 为什么不尝试发送AJAX请求? 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM