Hi all,
I have a very simple requirement which I am having a hard time fulfilling using core JavaScript, and I'm wondering if dojo would provide a better solution. I want to open a new window, and halt execution of the rest of my program until the DOM of the new window finishes loading. It's easy to find out when the DOM finished loading (using either an onload property, or just a try/catch to see if the element I'm looking for currently exists), but unfortunately, I can't figure out a nice way to implement the blocking i/o. I'm used to procedural languages, and so would my first instinct is to just loop until he's ready:
while(!windowref.document){
sleep(100)
}
The sleep function in there is important, because just doing a loop without some sort of pause locks up the browser, and prevents the new window from finishing loading. Of course, javascript does not have a sleep function, so I can't directly implement this. setInterval is close, but it does not block the rest of the script's execution.
The way I've currently overcome this problem is by breaking my script into two main functions: the first one which loads the new window, and the second, which gets called by the first after the window finishes loading. The problem is that this is entirely artificial; there's no reason to have my program broken into two parts except to accommodate the fact that I can't figure out a way to implement blocking i/o from scratch.
I'd greatly appreciate any advice anyone can offer on how best to implement this. Thanks!
Jake

I think in general, blocking
I think in general, blocking is a bad idea and leads to a poor user experience. So getting used to writing asynchronous code with callbacks may be the necessary evil. Dojo provides some nice mechanisms for dealing with callbacks in a loosely couple and comfortable way -- using dojo.Deferred or dojo.connect. Without a specific example of what you are doing, its hard to see which would be best. Perhaps something like:
}
function doSomethingAfter(){
}
dojo.connect(newWindow, "onload", doSomethingAfter);
(this is pseudo code at best, but you get the idea...)
-maulin
http://blog.medryx.org