原生JavaScript检验URL链接是否有效,正常访问

function getUrlState(URL){
  var xmlhttp = new ActiveXObject("microsoft.xmlhttp");
  xmlhttp.Open("GET",URL, false);
  try{
    xmlhttp.Send();
  }catch(e){
  }finally{
    var result = xmlhttp.responseText;
    if(result){
      if(xmlhttp.Status==200){
        return(true);
      }else{
        return(false);
      }
    }else{
      return(false);
    }
  }
}