Safari problem with onload handler of new Image() object

M

Martin Honnen

I was playing around with canvas support in recent Safari, Mozilla and
Opera (only version 9 preview) but run into issues with Safari related
to the very old DOM Level 0 Image object for preloading images.

When doing e.g.
var img = new Image();
img.onload = function (evt) {
alert(this);
};
img.src = 'whatever.gif';
I expect the this object in the onload event handler to be the img
object the event handler is attached to.

Not so with Safari it seems, the this object is the window object and
even the event object does not seem to give you any properties (like
target) to get the img object.

Complete test case is here:
<http://home.arcor.de/martin.honnen/safariBugs/imageOnloadThisObject1.html>

Can anyone confirm that?
I see it with Safari 1.2, 1.3, 2.0.

Does anyone know that problem? I don't see any reason to implement it
that way, rather seems a big bug to me.
Is anyone here close to Safari development to consider filing a bug at
the proper location?

Could anyone test whether the problem also occurs with Konqueror versions?
 
T

Thomas 'PointedEars' Lahn

Martin said:
I was playing around with canvas support in recent Safari, Mozilla and
Opera (only version 9 preview) but run into issues with Safari related
to the very old DOM Level 0 Image object for preloading images.

When doing e.g.
var img = new Image();
img.onload = function (evt) {
alert(this);
};
img.src = 'whatever.gif';
I expect the this object in the onload event handler to be the img
object the event handler is attached to.

Not so with Safari it seems, the this object is the window object and
even the event object does not seem to give you any properties (like
target) to get the img object.

Complete test case is here:
[...]
Could anyone test whether the problem also occurs with Konqueror versions?

Mozilla/5.0 (compatible; Konqueror/3.5; Linux 2.6.15.1-20060130.184242+0100;
X11; i686; de, en_US) KHTML/3.5.1 (like Gecko) (Debian package 4:3.5.1-1)

| Passed this object: [object IMG]
| this.tagName: IMG; this.src:
| http://home.arcor.de/martin.honnen/safariBugs/kiboInside.gif
| this object === window: false
| Passed event object: [object Event]
| event.target: [object IMG]; event.currentTarget: [object IMG]
| event.srcElement: [object IMG]
| this object === event.target: true
| this object === event.currentTarget: true
| this object === event.srcElement: true


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top