title: IE9 onbeforeunload called twice when window.location changed in button event... minimal reproduction
body: <p>I've been hammering and hammering at this and just can't get anywhere.</p>
  
  <p>I have a cancel button that does a "window.location = '404.htm';" when clicked. The onbeforeunload handler fires twice, but only if the user clicks "Stay on this page" to the first dialog. A normal navigation (page refresh, going to home page) the onbeforeunload handler only fires once.</p>
  
  <p>I've managed to repro the behavior with a minimal amount of HTML and script:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Test page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body onbeforeunload="return 'Unsaved changes';"&gt;
      &lt;form name="form1" id="form1"&gt;
          &lt;input id='cmdCancel' type="button" value="Cancel" onclick="window.location = '404.htm';" /&gt;
      &lt;/form&gt;
      &lt;script type="text/javascript"&gt;
          /*
           * Connecting the events via code makes no difference
           *
          document.forms[0].cmdCancel.onclick =
              function () {
                  alert('Clicked cancel. About to navigate...');
                  window.location = '404.htm';
              };
  
          window.onbeforeunload = function () {
              return "Unsaved changes";
          }; 
  
          */   
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>There are lots of hits for "onbeforeunload called twice" but no minimal reproduction and no actual solutions.</p>
  
  <p>Any suggestions? </p>
  
  <p>Thanks!</p>