The event after loading image on IE9

会有一股神秘感。 提交于 2019-12-02 10:35:50
marlenunez

It doesn't have to be after that line, since it will be asynchronous anyway, but here it is:

document.getElementById("id_image").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = document.getElementById("id_filepic").value;
document.getElementById("id_image").addEventListener('load', (function(i) {
    return function() {
        console.log(i, 'loaded');
    }, false);
})(i));

Source: Javascript Image onload event binding

Eitan

I want to participate my solution, I have found.

Well, the above is not compilable, and also 'onload' is not the correct event (it is not fired after using the "filter" command, as far as I investigated).

What I did is a little delay, with timeout command (about one second) like this :

    setTimeout(function () {
        alert("w: " + $("#id_image").width());
        alert("h: " + $("#id_image").height());
    }, 1000); 

(even 100 milliseconds is enough, but I check that out for very large images. 1 second is quite big not to fall by code on large images).

After the delay, I could retrieve the image width and height with no problem.

That's complete this issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!