[thelist] bug in Safari using onload on Image objects created thruJS?

Peter-Paul Koch gassinaumasis at hotmail.com
Thu Jan 29 04:09:36 CST 2004



>If I create an image using new Image, assign it a src property, and attach
>an onload event handler (either using the DOM0 method of assigning to the
>onload property or using the addEventListener() method), some properties of
>the event object in the event handler and the 'this' object don't appear to
>be correctly populated in Safari.  event.type is 'load' as it should be but
>event.currentTarget and event.target are both undefined but, in Mozilla,
>these return a reference to the Image object.  I'm not sure what 'this'
>contains in Safari (alerting it gives a blank string) but it should also
>contain a reference to the Image object as it does in Mozilla.
>
>I have a demo page at
><http://www.dithered.com/temp/safari_image_onload.html>.
>
>Is this a bug in Safari and is there any way to get a reference to the 
>Image
>object from inside the event handler?

OK, this is definitely messy.

I tried roughly the same, though I used

var dynImage = document.createElement('img');

instead of your

var dynImage = new Image();

This makes a LOT of difference. The this keyword works properly when you use 
createElement, BUT the loading of the image only starts *when it is inserted 
into the document*. So if you just create the image elements and wait for 
the onload alert, nothing happens.

As to your script, yes, I'd say this is a bug. Apparently Safari treats new 
Image() way different from createElement('img'). You can't append the image 
to the document, either, you need createElement for that.

I assume you filed a bug report on your page.

-------------------------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.quirksmode.org/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
------------------------------------------------------------------

_________________________________________________________________
Play online games with your friends with MSN Messenger 
http://messenger.msn.nl/



More information about the thelist mailing list