Is there a way to tell, after the fact, whether an image (placed with the <img>
tag, not via JS) has loaded correctly into a page? I have a gallery of head shots, and occasionally the third-party image server ends up serving up a 404. I can change the server-side code to use an onerror="showGenericHeadshot()"
, but I really want to avoid making changes to server-side code. Ultimately, I want to determine if an image is missing or broken and replace it with a generic "Image Not Found" graphic. Things I've tried:
Image.prototype.onerror = showGenericHeadshot
-- doesn't work for<img>
tags$('img[src*=thirdpartyserver.com]).error(showGenericHeadshot)
-- doesn't work in IE$('img[src*=thirdpartyserver.com]).css('backgroundImage','url(replacementimage.gif)')
-- works, but still doesn't get rid of the broken image icon in IE