PDA

View Full Version : add onload event for img



topcoder1
8 Aug 2007, 4:45 AM
I am trying to add an onload event for image, I tried two approaches below, none of them works, the image is loaded correctly though, but event is not triggered. what's wrong?
thanks



content= dh.append("img-id", {tag: 'img',
src: "http://doman/my.jpg",
onload: function(event){
alert(event);
}
});


content=Ext.get("img-id);

content.addListener('load',function(event){
alert('****'+event);
});

mystix
8 Aug 2007, 4:58 AM
that's a pretty vulgar alert... 8-|

in the 1st case, try onLoad instead of onload.

in the 2nd case, you're listening on the appended image's parent, not the image itself.
try this instead


Ext.get('img-id').on('load', function(e) {
alert(event);
});

topcoder1
8 Aug 2007, 2:01 PM
thanks! the second approach works. But the first one doesn't work. tried onload and onLoad.
and oops I forgot to take out the vulgar word before I post.. I'm sure all of us cuss when we debug... lol

mystix
8 Aug 2007, 5:44 PM
the first one probably needs to be


onLoad: [
"function() {",
"// bla bla bla",
"}"
].join("")


i.e. an inline function