GWT: 2.6.1
I would like to execute an action when an image is loaded (image src).
I tried this, but the onLoad event is never fired :
final Image img = new Image();
img.addLoadHandler( new LoadHandler()
{
@Override
public void onLoad( LoadEvent event )
{
//action
}
} );
img.setUrl( "/image.png" );
Then I tried this :
final Image img = Image.wrap( Document.get().createImageElement() );
img.addLoadHandler( new LoadHandler()
{
@Override
public void onLoad( LoadEvent event )
{
//action
}
} );
img.setUrl( "/image.png" );
And it worked... I don't understand why the first code do nothing.
Important: In this two examples, I don't put the Image object into the dom (= Image isn't attached).
In this question, it seems that the cause is that the Image isn't attached. But in my second sample code, the image isn't attached too ? right ?