<Doctype HTML public-wcdtd XHTML stricten httpwwwworgtrxhtmldtdxhtml-strictdtd> recently, we are working on web development. One of the requirements is to use JavaScript to obtain the size of the image to be loaded. Naturally, I thought of the IMG onload method. After the development is completed in Firefox, I went to IE for debugging and found that IMG onload events are not called in many cases.
My initial code is as follows:
VaR IMG = new image;
IMG. src = "test.gif ";
IMG. onload = function (){
Alert (IMG. width );
};
This code is okay, but why is onload not called by IE? Because ie caches the image and loads the image 2nd times, instead of being uploaded from the server, but from the buffer. Isn't the onload event not triggered for images loaded from the buffer? I tested the following code and succeeded ~
VaR IMG = new image;
IMG. onload = function (){
Alert (IMG. width );
};
IMG. src = "test.gif ";
I wrote onload to the front, and told the browser how to process the image first, and then specify the source of the image. This is normal. Therefore, it is not because IE does 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 IMG. onload. This reminds me of Ajax. When writing XMLHTTP, we specify the onstatechange callback function first and then send data. The truth is the same.
# JavaScript/ajax Columns