title: cancel HTA close after user clicks close button
body: <p>Many programs prompt users if they really want to exit after clicking the window exit button (the big red X in the upper right corner of the window). In HTML Applications (HTA files), we can do it too.</p>
  
  <p>However, I don't know how to cancel the close event that comes after the onbeforeunload. I tried <strong>event.preventDefault()</strong>, <strong>event.stopPropagation()</strong>, <strong>event.cancelBubble = true</strong>, <strong>window.event.bubbling = false</strong>, <strong>return false</strong>, but neither worked.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;head&gt;
  &lt;title&gt;Cancel Close&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;script type="text/javascript"&gt;
      function ask() {
          var answer = confirm("Quit program?");
          if (answer) {
              alert("Exiting...");
          } else {
  
              //window.event.preventDefault(); //method does not exist
              //window.event.stopPropagation(); //method does not exist
  
              window.event.cancelBubble = true; //quits anyway
              window.event.bubbling = false; //quits anyway
              return false; //quits anyway
          }
      }
  &lt;/script&gt;
  
  &lt;body bgcolor="#ECE9D8" style="overflow:auto" onbeforeunload="ask()"&gt;
      Some HTML... Click exit and cancel; the program exits anyway, but should not.
  &lt;/body&gt;
  </code></pre>
  
  <p>How to cancel the close operation if the user clicks cancel?</p>