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

  • Home
  • SEARCH
  • 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 8410839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:17:01+00:00 2026-06-10T00:17:01+00:00

I am aiming to check if image has been loaded successfully. It has been

  • 0

I am aiming to check if image has been loaded successfully. It has been working well in modern browsers but IE8 or 7 it is a terrible issue. Here is a sample code:

var img = new Image(),
    url = 'http://something.com/images/something.gif';

    $(img).attr('src', url).load(function() {
        if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
            alert('broken image!');
        } 
        else {
            alert('successfully loaded');
        }
    } 

Anyone has any idea to work around with this issue? Thanks in advace!

  • 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-06-10T00:17:03+00:00Added an answer on June 10, 2026 at 12:17 am

    You HAVE to set the onload handler BEFORE you set the .src value.

    In some versions of IE, if the image is in the browser cache, the load event will be fired immediately when the .src value is set. If your load handler is not already in place, you will miss that event.

    Also, naturalWidth and naturalHeight are NOT supported in older versions of IE so they will always be undefined. And, you should use onerror and onabort to catch the error conditions.

    There’s no need to use jQuery for this. You can just do this:

    var img = new Image(),
    
    img.onload = function() {
        alert("loaded successfully");
    }
    img.onerror = img.onabort = function() {
        alert("broken image");
    }
    // only set .src AFTER event handlers are in place
    img.src = 'http://something.com/images/something.gif';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been aiming to do something simple..but not sure of the best approach. I've
I'm working on a small java project aiming to transform a BitSet into several
I'm working with GNU assembler on i386, generally under 32-bit Linux (I'm also aiming
I'm working on a tool to simplify an application's deployment. Hence I'm aiming to
I'm aiming to create a set of objects, each of which has a unique
I am working on a Web based organisation tool. I am not aiming the
I'm experimenting with gcov using mingw gcc 4.4.0. I've been getting some interesting but
Here's what I'm aiming for, working 100% correctly in Firefox 7 . When I
I'm aiming for exactly this layout: http://jsfiddle.net/rQVmK/ ... but with the addition of another
I am aiming to create a .bat launcher that will execute a command line

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.