I have a big, complicated Javascript program that's doing some rather
complex things. One of the things it really has to do is to wait for the
browser to load something.
Because Javascript is all event-driven, the closest I seem to be able to
come is this:
loadMyFile("http://...insert url here...", function () {
alert("the file has loaded!");
});
That is, loadMyFile() executes asynchronously but registers a callback to
execute once the thing's loaded.
Unfortunately, while this works, it's a pig to program for. What I'd like is
for loadMyFile() to be synchronous: that is, it doesn't return until the
file has completely loaded.
(And I want to wait for other things apart from the file loading.)
It would appear that in order to do this I'm going to need multiple threads
of execution, somehow. I need to be able to have my main thread block, and
get woken up later by another thread. Is this at all possible?
Some experimentation would appear to suggest that all Javascript code on a
particular page, *including* code running in embedded iframes, appears to
execute in a single thread. Javascript on another page may or may not
execute in a different thread on my browser, but that's not terribly
important because I can't communicate across pages anyway.
Any suggestions?
I'm currently targeting IE6 and Firefox; I'd prefer standards-compliant
solutions, if any exist, but am willing to resort to hackery if I have
to...
--
+- David Given --McQ-+ "There is // One art // No more // No less // To
| dg@cowlark.com | do // All things // With art // Lessness." --- Piet
| (dg@tao-group.com) | Hein
+- www.cowlark.com --+