Connecting Tech Pros Worldwide Forums | Help | Site Map

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

stahl.karl@gmail.com
Guest
 
Posts: n/a
#1: Feb 10 '06
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!


alexey@shtokalo.net
Guest
 
Posts: n/a
#2: Feb 10 '06

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