473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Safari problem with onload handler of new Image() object


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
2 6396
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
On every web browser except Safari, this website works great. (Well, by "every" I mean Mozilla, Netscape, and Internet Explorer, for Mac and Windows). The site is: http://www.ruleofthirds.com ...
8
by: TheKeith | last post by:
I'm doing an image cycler but can't figure out why it keeps getting hung up on the third pic in the array? Here is what I have: ...
6
by: Krzysztof Kubiak | last post by:
I'm trying to make use of XMLHTTP object, but I've come across a problem. It seems that there is no way to create dynamic array of such XMLHTTP objects (to make several requests) and handle them...
1
by: Roger Shrubber | last post by:
Good day In an image onload handler, how do I access the image that just loaded? If the image is attached to the document, I can access it using the field window.event.srcElement. But I...
1
by: Adam Ratcliffe | last post by:
I'm trying to come up with a solution for detecting when an image, loaded by a script, has completely loaded. The Image.onload event is fired after the image has loaded in Firefox but before...
3
by: Joe Cox | last post by:
I am having a problem with style properties for dynamic images in Mac OS X Safari. By dymanic images, I mean images allocated with the javascript 'new Image()' call. With static images (created...
7
by: Tom | last post by:
I have an oo-type javascript program running perfectly on IE 6.0+, FF 1.5+, and Opera 7+ on Windows 98+, Linux (RH 9, FC 6), and Mac OS X. 4. As usual, the Safari browser is not working correctly,...
11
by: Stevo | last post by:
I've been using the unload event for a long time. I have this code, which I've abstracted and made into a stripped down simple test case below, and it works fine on the major browsers (IE5+,...
7
by: howardk | last post by:
I'm writing some code that loads a number of images, using the standard mechanism of assigning a src url to a newly constructed Image object, thus invoking the image-load operation. On a successful...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.