473,748 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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/imageOnloadThis Object1.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 6479
On 2006-02-01, Martin Honnen <ma*******@yaho o.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.a ppendChild(this ) doesn't work in place of the alert.
Complete test case is here:
<http://home.arcor.de/martin.honnen/safariBugs/imageOnloadThis Object1.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.currentTa rget: null
..event.srcElem ent: null
..this object === event.target: false
..this object === event.currentTa rget: false
..this object === event.srcElemen t: 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/imageOnloadThis Object1.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.currentTa rget: [object IMG]
| event.srcElemen t: [object IMG]
| this object === event.target: true
| this object === event.currentTa rget: true
| this object === event.srcElemen t: true
PointedEars
Feb 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2508
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 (the problem does not exist on the first page... just all the other pages, so you'll have to click on something to see the problem) The problem lies with images swapping on rollover. I use a small
8
3908
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: ---------------------------------------------------------------------------- --------------------------------- <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6
3264
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 properly. I was trying to use such code: <script lang="javascript"> function handleOnReadyStateChange() { if (this.readyState==4) {
1
3025
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 really don't want to attach the image to the document until it has loaded (I plan to use it to replace an existing visible low-res version of the same image). The onload handler is called for the unattached image, but the window.event.srcElement is...
1
10208
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 loading has completed in Internet Explorer. The function where I assign the onload event handler looks like this: var newImage = new Image(); function getImage(url) { var image = document.getElementById("theImg");
3
6693
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 with the html <img> tag), I can make the image visible or not, i.e. '<img style="visibility='hidden'" src='xxxx'/>'. But if I create the image dynamically with javascript: new Image() then try to modify the style, Safari chokes, and the Debug...
7
2553
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, and because it lacks an internal debugger, I'm completely unable to see what the problem is. So I downloaded that "Drosera" debugging program, but I'm finding it useless for the following reasons: 1) I cannot "Attach" it to Safari 2.0...
11
2456
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+, Firefox, Opera). It also works for all Safari versions before 3.1. It's as if they've deliberately made a change to prevent some actions in the unload handler. Has anyone heard of such a restriction? Here's the test case:
7
3158
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 load, an image.onload handler I've previously assigned will be called. Or should be at any rate. The problem is that I need to know inside the onload handler which particular image in the array invoked the handler. I'd be quite happy to know...
0
8826
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9316
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.