Phillip Pearson - web + electronics notes

tech notes and web hackery from a new zealander who was vaguely useful on the web back in 2002 (see: python community server, the blogging ecosystem, the new zealand coffee review, the internet topic exchange).

2005-7-13

Reloading images without flicker

Finally found how to refresh an image in a document without making the old image disappear while the new one loads. I know I'm going to forget this if I don't write it down, so...

foo = new Image();
foo.src = url_of_new_image;
foo.onerror = function_to_call_if_download_fails;
foo.onload = function_to_call_when_download_finishes;

Then stash foo away somewhere, and when the foo.onload function gets called, copy foo.src over to the image you want to refresh.