By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 781 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

Safari problem with onload handler of new Image() object

P: n/a

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?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2006-02-01, Martin Honnen <ma*******@yahoo.de> wrote:

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. Could anyone test whether the problem also occurs with Konqueror versions?
the alert appears to work with Konqueror,
but document.body.appendChild(this) doesn't work in place of the alert.
Complete test case is here:
<http://home.arcor.de/martin.honnen/safariBugs/imageOnloadThisObject1.html>


Konqueror 3.3.2 produced the following output

..
..Image object onload handler this object and event object check
..
..Passed this object: [object Image]
..
..this.tagName: undefined; this.src:
..http://home.arcor.de/martin.honnen/s...kiboInside.gif
..
..This object === window: false
..Passed event object: [object Event]
..event.target: null; event.currentTarget: null
..event.srcElement: null
..this object === event.target: false
..this object === event.currentTarget: false
..this object === event.srcElement: false
..

Bye.
Jasen
Feb 5 '06 #2

P: n/a
Martin Honnen wrote:
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>
[...]
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/s...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
Feb 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.