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 5983991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:18:37+00:00 2026-05-22T22:18:37+00:00

I have written a jQuery plugin called waitForImages . It basically gives the ability

  • 0

I have written a jQuery plugin called waitForImages. It basically gives the ability to run callbacks when images have loaded.

I recently received a feature request to somehow make the code notify when there is an error downloading an image.

Could the plugin call a function when an image is not found?

I thought about adding an extra argument that could be checked if the image was downloaded successfully or not.

image.onerror = function() {
     eachCallback.call(img.element, allImgsLoaded, allImgsLength, true);
}

Then the person could check the last argument to see if it is true, and if so, there was an error loading the image.

This idea smells to me though. What if I want to add an extra argument there later? Should the same callback be called for successful and failure of the image download?

I then thought about throwing an exception if the image is not found.

throw new Error(img.src ' + does not exist');

This however is not as flexible to catch, you’d need to call the plugin like so…

try {
   $('body').waitForImages();
} catch (exception) {
    // Which image didn't load?
    alert(exception.message);
}

What would be the best way to handle if an image didn’t load in my plugin?

  • 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-22T22:18:38+00:00Added an answer on May 22, 2026 at 10:18 pm

    I’d add a specific callback for error conditions.

    You already have this:

    $('selector').waitForImages({
        finished: function() {
            ...
        },
        each: function() {
           ...
        },
        waitForAll: true
    });
    

    You should consider changing it to:

    $('selector').waitForImages({
        finished: function() {
            ...
        },
        finishedError: function() {
            ...
        },
        each: function() {
           ...
        },
        eachError: function() {
           ...
        },
        waitForAll: true
    });
    

    You could also use “finishedSuccess”, if given, just to keep it consistent.

    I prefer this for a few reasons:

    1. It separates out error handling
    2. You can have a different set of arguments for success or failure callbacks
    3. You easily add callbacks for different errors (unlikely for this case)

    Please don’t throw exceptions. An uncaught exception will break JavaScript execution. Probably not something you’ll want to do just because an image didn’t load.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a jQuery plugin, but I want it to check if jQuery
I have written a jQuery plugin like this: jQuery(function($) { $.fn.myPlugin = function() {
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have written a site in Prototype but want to switch to jQuery. Any
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I have written some jQuery ajax code where I am sending a request to
I've written a jQuery plugin and it was working well for all version up
I am creating my own jQuery plugin. Here is the code which I have
I have facebox plugin to my jQuery, to make lightbox for me. I made
I have written jquery code to show description if I hover on a hyperlink.

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.