title: Javascript, pause/resume window.load event
body: <p>I have an unusual problem that is beyond my client side skill set.  I have an html page with two consecutive <code>script</code> tags in the body.  Both <code>script</code> tags fire an ajax request to retrieve content and then put it in the DOM.  I control the first <code>script</code> tag, and I don't have any control or knowledge about the second <code>script</code> tag.  I just know it makes an ajax call and put stuff in the DOM.  I also know that my tag is first.</p>
  
  <p>I want my script tag to fire immediately and pause/stop the second tag.  Then, contingent on what my ajax returns, I may choose to execute the second script tag.  How do I do this?</p>
  
  <p>I wrote a <a href="http://jsfiddle.net/SWkLX/1/" rel="nofollow noreferrer">fiddle</a> demonstrating my problem.  I substituted <code>settimeout</code>'s for ajax calls and <code>Math.random</code> for my decision.  Note that the <code>settimeout</code> duration for the first one (my one) is very long, 3 seconds, and the duration for the second one (the one I don't control is very short, .5 seconds.  What's happening now is that they are both running immediately.  The second message  comes in at .5 seconds, and the message from the first comes in at 3 seconds 50% of the time.</p>
  
  <p>I want the first script to run, wait 3 seconds, make a decision and either print the first message immediately, or call the second script which would wait an additional .5 seconds to print the second message.  I should never see both messages at the same time, and I should never see the second message before 3.5 seconds.</p>
  
  <p>Again, I don't know any knowledge over the contents of script two.  You could easily hide id=<code>ext_div</code> in this case, but I don't know what that id is.  That is not the answer I want.  I was thinking about grabbing the event on the first script and doing something to that, <code>stopPropagation</code> or something like that at the <code>TODO1</code> comment.  But that doesn't work.  Event if it did, I would need a <code>resumePropgation</code> function which I don't event think exists.</p>