Js pay attention to the onerror event analysis of img Images

Source: Internet
Author: User

After analysis, we found that the webpage contains code similar to the following:


Analysis: pay special attention to onerror. When the image does not exist, onerror is triggered, while onerror specifies a NoPic.gif image for img. That is to say, if an image exists, pic.gif is displayed. If the image does not exist, noPic.gif is displayed. However, the problem arises. If noPic.gif does not exist, the onerror will be triggered again, resulting in a loop.

NOTE: If an image exists but the network is not smooth, an onerror may also be triggered.

Solution:

First, remove the onerror code, change the onerror code to another, or make sure that the image in the onerror is small enough and exists.

Second:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
<! -
Function nofind (){
Var img = event. srcElement;
Img. src = ".../../sys/common/image/fileoperation/icon/default.gif ";
Img. onerror = null; do not keep beating
}
//->
</Script>
<Td align = "center"> $ {file. name} </td>

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.