Connecting Tech Pros Worldwide Help | Site Map

Update image immediately? How to avoid waiting until onload() finishes?

  #1  
Old February 10th, 2006, 04:45 AM
stahl.karl@gmail.com
Guest
 
Posts: n/a
I am trying to update an image when I load a page, then perform a bunch
of other actions that take a while. The problem is that the image does
not update until the entire function has finished running. Is there
some command that will allow me to force the first line to run, THEN do
the rest of the other stuff in the function? Here's an example of what
I am trying to do:

<script type=text/javascript>

function do_stuff_on_load {

mycell.innerHTML="<img src=" + image + ">"

...do a bunch of other stuff that takes a long time

}
</script>

<body onload=do_stuff_on_load()>
<table>
<tr>
<td id=mycell>
</body>


Thanks so much!

  #2  
Old February 10th, 2006, 07:45 AM
alexey@shtokalo.net
Guest
 
Posts: n/a

re: Update image immediately? How to avoid waiting until onload() finishes?


I think you can try to use setTimeout() function with small timeout
value to start image loading...

setTimeout('mycell.innerHTML="<img src="' + image + '">"', 200);

or split the onload action into fast and slow parts...

function do_stuff_on_load {

mycell.innerHTML="<img src=" + image + ">"

setTimeout('do_stuff_on_load_continue()', 200);

}

function do_stuff_on_load_continue {

...do a bunch of other stuff that takes a long time

}

Closed Thread