Is there a way to tell, after the fact, whether an image (placed with the `` 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:
1. `Image.prototype.onerror = showGenericHeadshot` -- doesn't work for `` tags
2. `$('img[src*=thirdpartyserver.com]).error(showGenericHeadshot)` -- doesn't work in IE
3. `$('img[src*=thirdpartyserver.com]).css('backgroundImage','url(replacementimage.gif)')` -- works, but still doesn't get rid of the broken image icon in IE
stackoverflow.com/questions/92720/…
以上就是How to tell if an image has loaded correctly的详细内容,更多请关注web前端其它相关文章!