收集了幾種判斷遠程圖片是否存在的方法
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>
<html>
判斷遠程圖片是否存在,不存在的話替換成設計家園的logo,代碼如下:
<IMG src="遠程圖片" onerror="javascript:this.src='/images/logo1.gif'">
asp判斷:
<%
url= "/images/logo1.gif"
'on error resume next
Set xmlHttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlHttp.open "get ",url,false
xmlHttp.send
if xmlHttp.Status <> 200 then
response.write "不存在"
else
response.write "存在"
end if
%>
設計家園 收集整理
新聞熱點
疑難解答