<html>
<body>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("您的浏览器不支持AJAX!");
return false;
}
}
}
}
function GetURL(url){
createXMLHttpRequest();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert('存在')
}
else{
alert('不存在')
}
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
</script><input type="button" onclick="GetURL('http://www.baidu.com/')" value="http://www.baidu.com/ 存在吗?"></input>
<input type="button" onclick="GetURL('http://www.error.com/')" value="http://www.error.com/ 存在吗?"></input>
</body>
</html>这个 在ie下 没问题,不知道为什么在ff下 baidu 为不存在求解。
跨域了?
那怎么 ie 和ff效果不一样?
在你的域下面写一个xx.php,接收一个url,然后在这个php中判断是否存在这个网址,再返回给js。也就是说,js请求的是本域的php页面,php请求外域的内容并将结果返回给js。
IE可以设置浏览器安全 也可以设置跨域;