原生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);
    }
  }
}

 

posted @ 2016-04-06 11:45  WilliamShaw  阅读(1212)  评论(0编辑  收藏  举报