Eventually /dev/null

Random thoughts from an emerging Programmer

Image.onload() Problems

Since a while 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:

1
2
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, this problem was fixed with 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 knows if it’s possible to get some real onload for Images in Opera, without any of the previously mentioned hack?
Or can Opera fix this problem? It’s working correctly in IE, why not in Opera?