function isExist(sURL) {
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP")
xmlhttp.abort();
xmlhttp.open("GET",sURL,false)
xmlhttp.send()
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) return true //url存在
else if (xmlhttp.status==404) return false //url不存在
else return false //其他状态
}
}
本文介绍了一个使用MSXML2.XMLHTTP对象检查指定URL是否存在的JavaScript函数。该函数通过发送GET请求并根据HTTP状态码判断目标URL的状态,从而实现验证URL有效性。

被折叠的 条评论
为什么被折叠?



