Use the OnError event of an Image object to determine that an error replaces the URL of the image object's SRC as the default picture.
<p> first case: Picture exists, normal display </p> <p> second case: Picture does not exist, show default picture </p>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
here is the decision through JS
Use JavaScript to determine whether the specified picture file exists:
If you judge This picture address exists.
If it does not exist, the picture is probed in a few seconds, and the prompt address is valid if the address is valid
Copy Code code as follows:
<script type= "Text/javascript" >
function isexist (URL)
{
x = new ActiveXObject ("Microsoft.XMLHTTP")
X.open ("Head", Url,false)
X.send ()
Return x.status==200
}
Alert (Isexist ("Http://www.jb51.net/logos.gif"))
</script>
The picture is present returns true above
Copy Code code as follows:
<script language= "JavaScript" >
var xmlhttp = new ActiveXObject ("Msxml2.xmlhttp");
xmlHTTP. Open ("Get", "Http://www.jb51.net/logos.gif", false);
xmlHTTP. Send ();
alert (Xmlhttp.responsetext);
</SCRIPT>
Picture exists returns GIF89AX
Copy Code code as follows:
Return the picture does not exist because the picture does not exist!