Click to See Complete Forum and Search --> : Waiting for an image to load


nille40
01-10-2003, 07:42 AM
Hi everyone,
is there anyway to wait for an image to load? I'm thinking something like this:


var image = document.createElement("IMG");
image.src = "...";
while(!image.complete);


This doesn't work, as the current thread gets locked at the while statement. It seems this thread is also loading the image. Is there anyway to to something like:


while(!image.complete)
{
Thread.sleep(xxx);
}


Or something like this? I need to wait for the image to load, as I need the dimensions.

Thanks on advance,
Nille

pyro
01-10-2003, 07:45 AM
Try this.

http://www.dynamicdrive.com/dynamicindex4/preloadimage.htm

nille40
01-10-2003, 07:57 AM
Thanks for replying!

This doesn't work, though. I need to wait for the image without occupying the thread. The 'window.setTimeout' starts a new thread, meaning that the thread I'm loading from continues. I'm depending on the image dimensions, and therefor the images must be loaded, and unfortunaly, they can't be preloaded, as I'm manipulating the images on the server (depends on 'runtime' variables).

Any suggestions?
Nille