JavaScript implementation of image fault-tolerant processing

Source: Internet
Author: User
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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.