Javascript| fault-tolerant before a product display page for people to do, need to place a large number of local or foreign pictures, due to the old data there are some invalid picture path, resulting in slow web pages can not load, wrote a large section of JS code to verify the validity of the image path, but because the external picture is likely because of the server, Network and other reasons, it is still possible to open and lead to a half-day page to all load, so you need to do a fault-tolerant image processing:
"Absmiddle" >, this way, if the picture does not load normally, it will automatically show Error.gif, save a big xx in there!
Code content: Var Strimageurl=document.form1.info_img.value;
if (strimageurl.length>0)
{
var regexpimageurl = Strimageurl.match (/^http:\/\/[a-za-z0-9]+\.[ a-za-z0-9]+[\/=\?%\ -&_~ ' @[\]\ ': +!] * ([^<>\ "\"]) *$/);
var imagetype = strimageurl.substr (strimageurl.length-4,4). toLowerCase ();
if (Regexpimageurl = null)
{
Alert ("Error: Incorrect picture address format");
Document.form1.info_img.focus ();
return false;
}
if ((imagetype!= ". jpg") && (imagetype!= ". gif") && (ImageType!= ". bmp") && (ImageType!= ". png") ))
{
Alert ("Error: Your address is not linked to a picture?!") ");
Document.form1.info_img.focus ();
return false;
}
}