<script>
function check(url)
{
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("post",url,false);
xmlhttp.send();
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
return true;
}
else
{
if(xmlhttp.status==404)
return false;
return xmlhttp.statusText
}
}
}var url="http://192.168.1.3/test/1.htm";
var flag=check(url);if(flag==true)
{
location='a.html'
}
else
{
if(flag==false)
{
location='b.html';
}
else
{
alert(flag);
}
}
</script>
function check(url)
{
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("post",url,false);
xmlhttp.send();
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
return true;
}
else
{
if(xmlhttp.status==404)
return false;
return xmlhttp.statusText
}
}
}var url="http://192.168.1.3/test/1.htm";
var flag=check(url);if(flag==true)
{
location='a.html'
}
else
{
if(flag==false)
{
location='b.html';
}
else
{
alert(flag);
}
}
</script>
虽然看的不是很懂,能否解释一下,小弟是初学者
我大致觉得好像是根据服务器返回页面不存在的404错误来选择页面
但是还有一个问题,就是当这个a.html是在另外的一台服务器上的页面,而这台服务器恰好关闭的时候怎么判断呢?这个也可以判断的吗?
如果是ftp的呢?比如ftp://192.168.1.3/test/1.htm又怎么识别是否存在呢?
function check(url)
{
try
{
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("post",url,false);
xmlhttp.send();
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
return true;
}
else
{
if(xmlhttp.status==404)
return false;
return xmlhttp.statusText
}
}
}
catch(e)
{
alert(e.description+',这可能是因为'+'您要请求的站点已经关机');
}
}var url="http://192.168.1.2/test1/111.htm";
var flag=check(url);if(flag!=null&&typeof(flag)!='undefined')
{
if(flag==true)
{
location='a.html'
}
else
{
if(flag==false)
{
location='b.html';
}
else
{
alert(flag);
}
}
}
</script>