[Dojo-interest] Image onload not firing in Safari

Peter Higgins dante at dojotoolkit.org
Tue May 1 11:08:19 EDT 2012

There are weird issues relating to image.onload x-browser. The "proper" way to avoid all issues is to connect to image.onload _before_ setting the src.  In the context of dojox/gfx, that may be a little bit more complicated. I'm not sure what createImage() is doing under-the-covers (but a dive into the code on your part might reveal something). 

Something like:

var img = surface.createImage({ w: …, h: …, x: x, y: y });
img.connect("load", function(e){

img.src = "icon.png"; 

This assumes the .src attribute can be set in such a manner on a "GFX Image". Worst case you can cache the "preload" the image src, and onload there attach the image to the surface. Something like:

var img = new Image();
var co = dojo.connect(img, "onload", function(e){
	surface.createImage({ ….., src: "icon.png" });
img.src = "icon.png";



On May 1, 2012, at 9:29 AM, Richard Fairhurst wrote:

> Hi,
> Dojo novice here but liking it very much.
> I'm working with dojox.gfx and attaching images to a surface. I need to 
> examine the image after it's loaded, so have attached an onload handler 
> like this:
> var sprite=surface.createImage({ width:24, height:24, x: x, y: y, src: 
> "icon.png" });
> sprite.connect("onload", this, function(event) { 
> console.log("onLoad",event); } );
> It works fine in Firefox, but the onload event never fires in Safari (OS 
> X, 5.1.1). I wondered if it was a timing issue (i.e. the image was 
> loading before sprite.connect executed), but referencing a slow-loading 
> image on a remote server, even with a random query-string attached, 
> makes no difference. Safari's Web Inspector shows that a "load" event 
> listener has successfully been attached to the image.
> Any thoughts?
> cheers
> Richard
> ________________________________________________________
> Dojotoolkit: http://dojotoolkit.org
> Reference Guide: http://dojotoolkit.org/reference-guide
> API Documentation: http://dojotoolkit.org/api
> Tutorials: http://dojotoolkit.org/documentation
> Dojo-interest at mail.dojotoolkit.org
> http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

More information about the Dojo-interest mailing list