What should I do if IMG does not support onload labels for webpage standards?

Source: Internet
Author: User

The IMG does not support the onload tag. What should I do? I remember someone asked me before, but I didn't pay attention to this yet. now we finally have this problem. because the IMG tag does not have an onload event. so UBB CodeThe onload used by IMG in processing large images is adaptive, so this method cannot be used.
However, after testing, the body can still carry the onload event, so the solution is to process too large images after all the pages are loaded.

So I used js to write a simple code related code function reimgsize (){
For (j = 0; j <document. Images. length; j ++)
{
Document. Images [J]. width = (document. Images [J]. width> 420 )? "420": Document. Images [J]. width;
}
}

Add onload = "reimgsize ()" to the body.

Tested on Mozilla and IE.
Here, we will add about image self-adaptation. Mozilla is doing better than IE, because CSS can be used to control image self-adaptation.
We all know that Mozilla supports a max-width CSS syntax. Therefore, we define the global style of the image in this way.

Related code IMG {
Max-width: 100%; Height: auto;
}

In this way, the image automatically adapts to its size in the Div or table.

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.