I was looking for a function that checks if the URL is an image or not, and I found this:
function checkImage(imageSrc, good, bad) {
var img = new Image();
img.onload = good;
img.onerror = bad;
img.src = imageSrc;
}
checkImage("foo.gif", function(){ alert("good"); }, function(){ alert("bad"); } );
it works alright, but the author did not explain how it works, and I'm a bit baffled,
how does img.onload=good knows what function to activate, and on the other hand img.onerror=bad, how does it work?
thank you for the help!