Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1098391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:34:23+00:00 2026-05-17T00:34:23+00:00

Is there a way to tell, after the fact, whether an image (placed with

  • 0

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:

  1. Image.prototype.onerror = showGenericHeadshot — doesn’t work for <img> 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:34:23+00:00Added an answer on May 17, 2026 at 12:34 am

    Unfortunately, I’m not able to accept either @TJ Crowder’s nor @Praveen’s excellent answers, though both do perform the desired image-replacement. @Praveen’s answer would require a change to the HTML (in which case I should just hook into the <img> tag’s own error="" event attribute. And judging by network activity, it look like if you try to create a new image using the url of an image that just 404ed in the same page, the request actually does get sent a second time. Part of the reason the image server is failing is, at least partly, our traffic; so I really have to do everything I can to keep requests down or the problem will only get worse..

    The SO question referred to in @danp’s comment to my question actually had the answer for me, though it was not the accepted answer there. I’m able to confirm that it works with IE 7 & 8, FF and webkit browsers. I’m doubtful it will work with older browsers, so I’ve got a try/catch in there to handle any exceptions. The worse case will be that no image-replacement happens, which is no different from what happens now without doing anything. The implementation I’m using is below:

    $(function() {
        $('img[src*=images.3rdparty.com]').each(
            function() {
                try {
                    if (!this.complete || (!$.browser.msie && (typeof this.naturalWidth == "undefined" || this.naturalWidth == 0))) {
                        this.src = 'http://myserver.com/images/no_photo.gif';
                    }
                } catch(e) {}
            }
        );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to tell GCC to not initialize a particular global array
Is there a way to tell excel to not display non-significant series in a
Is there a way to tell Visual Studio 2005 to not rearrange your SSIS
is there some way to tell VIM place the cursor at some position after
Is there a way to tell jQuery that you want what ever comes after
Is there a way to tell GDB to break right after a given function
Is there any way to tell visual studio to not include a project when
In Perl, is there any way to tell which .pl script has initialized this
Is there any way to tell db4o to call class default constructor while activating
Is there a way to tell ifort or gfortran to just try to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.