方法一:
function ()
{
var oReq = new ActiveXObject("Microsoft.xmlHTTP")
oReq.open("Get","UploadFiles/2007829144941621.gif",false);
oReq.send();
//alert(oReq.status)
if(oReq.status==404)
alert('不存在');
else
alert("存在")
}
方法二:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JavaScript判断远程图片是否存在,不存在则替换指定图片</title>
</head>
<body>
<p>判断百度的LOGO是否存在:<br>
<IMG src="http://www.baidu.com/img/baidu_logo.gif" οnerrοr="javascript:this.src='/images/logo.jpg'"></p>
<p>如果不存在,则替换成fengfly.com 的 logo:<br><IMG src="http://www.baidu.com/img/baidu_logo11.gif" οnerrοr="javascript:this.src='/images/logo.gif'"></p>
</body>
</html>
<p>判断远程图片是否存在,不存在的话替换成默认的图片,代码如下:</p>
<p>第一种情况存在:<IMG src="http://www.163.com/images/neteaselogo.gif" οnerrοr="javascript:this.src='http://www.361du.net/Images/Logo.gif'"></p>
<IMG src="http://www.163.com/images/neteaselogo.gif" οnerrοr="javascript:this.src='http://www.361du.net/Images/Logo.gif'">
<p>第二种情况不存在,替换成本站的logo:<IMG src="http://www.163.com/images/neteaselogo1.gif" οnerrοr="javascript:this.src='http://www.361du.net/Images/Logo.gif'"></p>
<IMG src="http://www.163.com/images/neteaselogo1.gif" οnerrοr="javascript:this.src='http://www.361du.net/Images/Logo.gif'">
方法三:
收集了几种判断远程图片是否存在的方法
js判断:
<script language=javascript>
function IsExist(url)
{
x = new ActiveXObject("Microsoft.XMLHTTP")
x.open("HEAD",url,false)
x.send()
return x.status==200
}
alert(IsExist("/images/logo1.gif"))
</script>
l