title: Pause function execution until another function returns
body: <p>I am wanting to replace Magento's implementation of the alert() and confirm() dialog boxes. While the alert() replacement was trivial, I am unsure of how to handle the confirm() dialog. Is there a way to prevent JavaScript from continuing until a function is returned? Will this require looping that could crash a browser?</p>
  
  <p>So for example, I need to replace code like this:</p>
  
  <pre><code>&lt;form action="" method="POST"&gt;
     &lt;input type="submit" onclick="return confirm('Are you sure?');" value="Delete"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>with...</p>
  
  <pre><code>&lt;form action="" method="POST"&gt;
     &lt;input type="submit" onclick="return myCustomConfirm('Are you sure?');" value="Delete"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Or other scenarios such as:</p>
  
  <pre><code>&lt;script&gt;
     var delete = confirm('Are you sure?');
     if (delete) {
         doSomething();
     }
  &lt;/script&gt;
  </code></pre>
  
  <p>with...</p>
  
  <pre><code>&lt;script&gt;
     var delete = myCustomConfirm('Are you sure?');
     if (delete) {
         doSomething();
     }
  &lt;/script&gt;
  </code></pre>
  
  <p>In both scenarios, myCustomConfirm() will open a Bootstrap modal where the user must click "Okay", "Cancel", or close the modal. The value returns true if "Okay" and false if otherwise.</p>
  
  <p>I don't want to do callbacks as that will cause more refactoring than desirable. Is this possible to do in another way?</p>
  
  <p>Thanks!</p>