Cross-browser event handling

In the jQuery documentation for the event download http://api.jquery.com/load-event/ says Can cease to fire for images that already live in the browser cache. Is any information available on this subject, such as which browsers it affects, and in which situations?

+3
source share
1 answer

I'm not sure which browsers are affected, but they are easy to check.

var img = new Image();
img.src = "foo.jpg";
if (img.complete || img.readyState === 4) {
    // image is cached
    doneCallback();
}
else {
    $(img).on('load',doneCallback);
}

UPDATE

If you change the code around, it will constantly trigger a download event in all browsers.

var img = new Image();
$(img).load(doneCallback);
img.src = "foo.jpg";
+10
source

All Articles