473,395 Members | 1,377 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,395 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 6407
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.