[Javascript] Order of script-processing

SkyScanner skyscanner at eircom.net
Mon Sep 26 04:31:09 CDT 2005


>> I seem to remember that in the past we have talked about the order that JS
>> actually processes its commands, and the results are not always what you
>> might expect.
>>
>> I've just come across that now, and can't work out a way to fix it. I have a
>> very slow routine that takes about 5 seconds to process even on a P4 2.4Ghz
>> machine. My idea was to have a 'loading - please wait' gif who's visibility
>> is initially set to 'hidden'. At the crucial point, I would make the gif
>> visible, do the routine, then make the gif 'hidden' once more.
>>
>> However, when I initiate this process by clicking on a button, the gif
>> doesn't display at all. Hmm - why would that be? Removing the 'make the gif
>> hidden once again' code reveals that when the button is clicked, the gif is
>> not made visible until the slow routine has completed, which means there's
>> no point in doing it! This occurs even though the code is
>>
>> show_the_gif();
>> slow_routine();
>> hide_the_gif();
>>
>> Any thoughts ?


From: "Peter-Paul Koch" <pp.koch at gmail.com>
> Most browsers (except Opera) change the visible display of the page
> only when all scripts have exited completely. Solution: use a timeout:

function show()
{
  gif.src = 'pleasewait.gif'; // or whatever
  setTimeout('slow_routine()',10);
}

> Now the script exits after the gif has been set and the browsers show
> it. Then the slow routine kicks in. Result: user sees Please Wait.



Hi - I got it working after a bit of experimentation. I found that it would only work properly if I placed a timeout around the slow routine *and* the hide routine.


showGif('icon_5');
setTimeout("slowRoutine()",10);
setTimeout("hideGif('icon_5')",10);


One strange thing happens, though. My gif is an animated gif:  showing the word 'loading' and a moving bar. However, when it is displayed as described above, the animation does not happen - it just stays still. I can live with that, though.

Thanks,
Tim in Ireland
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050926/37456b1e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 1278 bytes
Desc: not available
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050926/37456b1e/attachment.gif>


More information about the Javascript mailing list