How to tell if an image has loaded correctly

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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏