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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:42:59+00:00 2026-05-25T17:42:59+00:00

I am looking for a way to implement this for as many browsers as

  • 0

I am looking for a way to implement this for as many browsers as possible:

var image = new Image();
image.addEventListener("load", function() {
    alert("loaded");
}, false);
image.src = "image_url.jpg";

This didn’t work in IE so I googled and found out that IE’s lower than 9 do not support .addEventListener(). I know there is a jQuery equivalent called .bind() but that doesn’t work on an Image(). What do I have to change for this to work in IE too?

  • 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-25T17:42:59+00:00Added an answer on May 25, 2026 at 5:42 pm

    IE supports attachEvent instead.

    image.attachEvent("onload", function() {
        // ...
    });
    

    With jQuery, you can just write

    $(image).load(function() {
        // ...
    });
    

    When it comes to events, if you have the possibility of using jQuery I would suggest using it because it will take care of browser compatibility. Your code will work on all major browser and you don’t have to worry about that.

    Note also that in order to the load event being fired in IE, you need to make sure the image won’t be loaded from the cache, otherwise IE won’t fire the load event.

    To do this, you can append a dummy variable at the end of the url of your image, like this

    image.setAttribute( 'src', image.getAttribute('src') + '?v=' + Math.random() );
    

    Some known issues using the jQuery load method are

    Caveats of the load event when used with images

    A common challenge developers attempt to solve using the .load()
    shortcut is to execute a function when an image (or collection of
    images) have completely loaded. There are several known caveats with
    this that should be noted. These are:

    • It doesn’t work consistently nor reliably cross-browser
    • It doesn’t fire correctly in WebKit if the image src is set to the
      same src as before
    • It doesn’t correctly bubble up the DOM tree
    • Can cease to fire for images that already live in the browser’s
      cache

    See the jQuery docs for more info.

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

Sidebar

Related Questions

I'm looking for a way to implement this design in wxPython on Linux... I
Looking for some guidance on the best way to implement this scenario: I have
Looking for some advice on the best way to implement localization along with client
I'm looking for a best way to implement common Windows keyboard shortcuts (for example
What's the best way to implement the enum idiom in Ruby? I'm looking for
I'm looking for the simplest, most straightforward way to implement the following: The main
I'm looking to implement a way to keep files private so they cant be
I'm looking for a good way to implement reusable buttons in CSS on my
I'm looking to implement colour filters to images in a similar way to the
I'm looking for a way to implement consecutive animations using nested animation blocks. Somewhat

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.