After a button click, an image is started being loaded. What I want: when the image is fully loaded, a function is being called.
I know this question has been asked before, but every answer suggests to use the onload
event, which isn't entirely correct. According to the W3C spec, onload
is not a valid event for IMG elements. It wouldn't bother me very much if not for the fact that in some cases the event isn't fired.
Everything works fine except if the image weights much and the loading process takes some time (for example 20s). I guess the onload
event may have some maximum waiting time set. Example code with a heavy image (tested on Chrome, you have to clear the cache to test it again, and, if you have some super fast net, you may need to test it with even bigger image):
$(new Image()).attr('onload', 'worksFunc()').attr('src', "http://wallpaperus.org/wallpapers/04/151/outer-space1-1472x6429-wallpaper-1634552.jpg").appendTo($('body'));
The solution may be in jQuery, but not necessarily.