One thing to note, if the image is put into an element that has style display:none, events will not fire on IE. In my app, I actually want to load images but not display them until they are fully loaded. To accomplish this (across all browsers), I first load the image in a 1x1 pixel DIV that has style overflow:hidden, and then upon receiving the load event move the image into the element where I want it.
On Jul 16, 5:49 pm, "brett.wooldridge" <[email protected]> wrote: > I don't think you need to force a unique URL. Receiving an image from > the cache can be problematic on some browsers wrt events, but this has > always worked for me (on all browsers I've tested)... > > final Image img = new Image(); > img.addLoadHandler(...); > img.addErrorHandler(...); > > panel.add(img); // this panel must be in the DOM, i.e. the image must > be attached to the DOM at this point > > DeferredCommand.addCommand(new Command() { > public void execute() { > img.setUrl(url); // set the Image URL in a deferred command > } > > }); > > As I said, this works for me, even in IE. You can make a helper class > that takes a container and image, and performs the deferred logic. > > On Jul 16, 1:26 pm, davidRoe <[email protected]> wrote: > > > > > thanks, Brett. > > > right after posting, I had stumbled upon addErrorHandler() while > > browsing the GWT source and tried exactly this, without any joy. > > however, with you re-iterating that this was the solution, I tried > > again, forced a unique URL to avoid the image being loaded from cache, > > and success. > > > On Jul 15, 12:04 am, "brett.wooldridge" <[email protected]> > > wrote: > > > > Almost exactly the same way. If you are only interested in failure: > > > > public void foo() { > > > image.addErrorHandler(new ErrorHander() { > > > public void onError(ErrorEvent event) { > > > ... > > > } > > > }); > > > > } > > > > Or if you are interested in both success and failure, your class can > > > implement both interfaces or you can to synthesize a third interface > > > that combines them: > > > > public void foo() { > > > interface WinAndLose extends LoadHandler, ErrorHander { } > > > > WinAndLose wal = new WinAndLose() { > > > public void onLoad(LoadEvent event) { > > > } > > > > public void onError(ErrorEvent event) { > > > ... > > > } > > > } > > > > image.setErrorHandler(wal); > > > image.setLoadHandler(wal); > > > > } > > > > On Jul 15, 3:21 pm, davidroe <[email protected]> wrote: > > > > > how can I determine that an image failed to load, due to perhaps a > > > > network error? > > > > > I used to use image.addLoadListener(new LoadListener() { > > > > public void onLoad(Widget sender) { > > > > ... > > > > } > > > > public void onError(Widget sender) { > > > > ... > > > > } > > > > > } > > > > > and anything that arrived through onError() was deemed a problem. > > > > > how can I achieve the same thing with addLoadHandler(new LoadHandler > > > > ()) and the associated LoadEvent? > > > > > thanks, > > > > /dave --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
