title: onbeforeunload event not executed when the page is closed during Javascript running
body: <p>The scenario I have is a bit complicated, but I can reproduce my problem shortly in the following example:</p>
  
  <pre><code>&lt;html&gt;
   &lt;head&gt;
    &lt;script type="text/javascript"&gt;
    function fnUnloadHandler() {
         alert("Unload event.. session termination request to be sent to server");
    }
    function f() { 
         i = 1;
         while(1==1){
            i++;
         }
     }
    &lt;/script&gt;
   &lt;/head&gt;
  &lt;body onbeforeunload="fnUnloadHandler()"&gt;
   &lt;p&gt;&lt;button href="#" onClick="f();" &gt;do&lt;/button&gt;&lt;/p&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now; once the "do" button is clicked, f() get's the browser in an infinite loop. during that time if I close the page I get two different behaviours :</p>
  
  <ul>
  <li><strong>On IE7</strong>: Javascript execution is terminated, the onbeforeunload event is triggered and alert is shown then page is closed.</li>
  <li><strong>On IE9</strong>: Javascript execution is terminated, the onbeforeunload event is <strong>NOT</strong> triggered and <strong>NO</strong> alert is shown and page closed directly.</li>
  </ul>
  
  <p>I would like to know why IE9 is not handling the onbeforeunload correctly in this case .. is there any fix/patch to apply to IE9 to fix this problem?</p>
  
  <p>Many thanks in advance!</p>
  
  <p>Firas</p>