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

S

stahl.karl

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!
 
A

alexey

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

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top