The scenario I have is a bit complicated, but I can reproduce my problem shortly in the following example:
<html>
<head>
<script type="text/javascript">
function fnUnloadHandler() {
alert("Unload event.. session termination request to be sent to server");
}
function f() {
i = 1;
while(1==1){
i++;
}
}
</script>
</head>
<body onbeforeunload="fnUnloadHandler()">
<p><button href="#" onClick="f();" >do</button></p>
</body>
</html>
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 :
- On IE7: Javascript execution is terminated, the onbeforeunload event is triggered and alert is shown then page is closed.
- On IE9: Javascript execution is terminated, the onbeforeunload event is NOT triggered and NO alert is shown and page closed directly.
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?
Many thanks in advance!
Firas