Solution to IMG. onload failure in IE

Source: Internet
Author: User

Original

$ ("# Qrcode "). on ("LOAD", function () {$ (". loading "). hide (); alert (1) ;}// or document. getelementbyid ("qrcode "). onload = function () {$ (". loading "). hide (); alert (1 );}

It seems that there is no problem, but why is onload often not called in IE? Because the browser caches images, the second loaded image is not transmitted from the server and will not initiate a request. However, the complete attribute of the image will be added. Alert (1); it will be executed every time, so the guess is wrong.

Modify the Code as follows:

VaR IMG = new image (); IMG. onload = function () {document. getelementbyid ("qrcode "). setattribute ("src", this. SRC) $ ("# loading "). hide ();} IMG. src = "/img/img.jpg ";

The onload event is written before assigning a value to the SRC of the imgage object. It is normal to first tell the browser how to process the image and then specify the source of the image.

Therefore, it is not because the IE browser did not trigger the onload event, but because the loading speed of the buffer is so fast that the onload event has been triggered when it is not running to OBJ. onload.

 

Solution to IMG. onload failure in IE

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.