In the Web development in the acquisition of the picture is very normal things, the picture before loading is not get the picture of the width of the high, after the load is completed before you can get the width of the picture itself, for example:
Copy Code code as follows:
var img = new Image ();
IMG.SRC = "Loading.gif";
Img.onload = function () {
alert (img.width);
};
OK? This code looks no problem, but in IE there will be a bug, IE is the first time to open the time no problem, the second use of this method on the tragedy, IE did not respond, even if the Refresh page is the same. Because IE will cache the picture, the 2nd time to load the picture, not from the server upload, but from the buffer in Riga.
Write the OnLoad method first, then specify the URL of this picture, this is normal. Therefore, not IE did not trigger the OnLoad event, but because the speed of loading the buffer too fast, so that did not run to the Img.onload, the onload event has been triggered. That's OK.
Copy Code code as follows:
var img = new Image ();
Img.onload = function () {
alert (img.width);
};
IMG.SRC = "Loading.gif";