Since awhile now I’m working with Javascript. I have to say that it’s for sure not that hard to write cross-browser Source Code like it’s still with CSS. But some parts aren’t easy to get them working. A recent problem is indeed the image.onload. At first it’s obviously that you should register an onload EventListener, before you assign an Image, like this:

image.onload = function() { alert("let's do something in here!");};
image.src = "myURL";

As it’s quite possible that the other way around, the picture is already loaded before the EventListener is registered.
But Hey! That’s no reason to make this mistake a few times…Now after you solve that self-made problem you can run into the next one! Opera calls the onload Event, only if the Object is newly created or the Image loaded isn’t already cached. That’s the state of Opera 7.5, as I read several times on various sites, that this problem was fixed within Opera 8.x. But now it seems that this Problem is back with Opera 9.26+( or earlier…).
Unfortunately my Script needs to be noticed everytime a new Image is loaded, although it may already be cached. The only way I’m aware of getting what I want is to disable the Cache of Opera, through Opera’s settings or per HTTP Header. Ok another way would be a function which looks the whole time if the image is changing, but both aren’t that what I’m searching for. Someone know if it’s possible to get some real onload for Images, in Opera, without any of the previously mentioned “hacks”?
Or can Opera fix this problem? It’s working correctly in IE, why not in Opera?

Tags: none

Tags: IE, Javascript, opera, problem
2 Responses to “Image.onload() Problems”
  1. Tim says:

    I suggest checking somethin like "img.width" – if the property is present and > 0, the image is already loaded

  2. Arif says:

    var img = new Image();
    img.onload = function(){
    image.src = “myURL”;

    This ll work.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Bad Behavior has blocked 2293 access attempts in the last 7 days.