"); $(imgLoader).attr("src", "http://localhost/malevil/Content/Images/img_adrenalin.jpg"); $(imgLoade...">

JQuery bind ("load")

var imgLoader = $("<img />"); $(imgLoader).attr("src", "http://localhost/malevil/Content/Images/img_adrenalin.jpg"); $(imgLoader).unbind('load'); $(imgLoader).bind('load', function () { alert("event fired"); }); 

But this only works in chrome, where is the problem? In IE, Firefox and Opera boot events never fired.

+6
source share
2 answers

You need to bind the load event before setting the src property.

As a side note, there are known issues with the upload event on images that you need to know about:

And, quoting the jQuery manual on load() :

  • It does not work consistently, reliable cross browser
  • This is not correct to run in WebKit if the src image is set to the same src as before
  • This is wrong DOM tree
  • You can cease fire for images that already live in the browser cache
+12
source

I would set the handler before which you set the src attribute - it could be that the image is loading before your event handler is installed.

+3
source

Source: https://habr.com/ru/post/886811/


All Articles