JS Note img Image onerror Event Analysis _javascript Tips

Source: Internet
Author: User
After analysis, found in the Web page is similar to the following code:


Analysis: Pay special attention to onerror, when the picture does not exist, will trigger OnError, and OnError for IMG To specify a nopic.gif picture. That is to say, the picture exists to display pic.gif, the picture does not exist will show nopic.gif. But the problem is, if nopic.gif does not exist, then continue to trigger onerror, resulting in loops, so there are errors.

Description: If the picture exists, but the network is not smooth, it may also trigger onerror.

Workaround:

The first::. Remove the OnError code, or change the onerror code for other, or make sure the picture in onerror is small enough and exists.

The second type:
Copy Code code as follows:

<script type= "Text/javascript" >
<!–
function Nofind () {
var img=event.srcelement;
Img.src= ". /.. /.. /sys/common/image/fileoperation/icon/default.gif ";
Img.onerror=null; Control don't keep beating
}
–>
</script>
<TD align= "center" >${file.name}</td>

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.