Picture failed to load, resulting in browser compatibility issues

Source: Internet
Author: User
The website often encounters the problem that the picture load fails, the IMG has the address, but the address opens is wrong. The situation is as follows:

Different browsers to handle the wrong picture is not the same, and some simply show the difference, such as IE, some show a broken picture, and some is to a relatively large default map, such as the PC-side of Firefox, iOS Safari, as well as the UC browser Android. This in the phone will cause the left and right sides of the picture highly inconsistent! The following figure:

Solution

In fact, this solution is very simple, to determine when the picture load failed to give a default diagram can be, do not let the browser use its own default diagram.

 
derivative issues 

Because the picture load failed to enter the default diagram, then the default diagram load failed to do? Isn't this going into a dead loop?

The simplest solution is to make sure that the diagram in the onerror is open and guaranteed to be small! There will be no problem!. This method is also the most effective way!

If you can't guarantee that, then, can only rely on the function to solve this problem!

The idea is:

When the picture fails to load, enter the onerror, the Judge onerror picture is not able to load, in the onerror of the picture triggered OnError, set onerror to null.

The code is as follows:

   



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.