0

i have a simple page running with asp.net mvc

When i click f5 or ctrl + f5 only in FF, server is hitted before "onunload" javascript function is called. it is working as expected in IE. Any knowhow?

Behaviour is like this: 1- Notify javascript function is called, 2- Server side code is called and page is refreshed 3- onunload javascript function is called.

what i expect is 3.step to run before step 2 as IE does.

 <head runat="server">
    <title>Serdar</title>
    <script src="<%=Url.ContentV("~/Scripts/JQuery/jquery-1.6.4.js")%>" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            window.onbeforeunload = NotifyClosing;
            window.onunload = UnLockDraftOrder;
        });

        function NotifyClosing() {
            alert('closing');
        }

        function UnLockDraftOrder() {

            alert('unlock order');
        }
    </script>
</head>
<body>
    <div>
    serdar
    </div>
</body>
</html>
Serdar
  • 71
  • 1
  • 3

1 Answers1

1

The browser doesn't actually know whether the page will unload until it hits the server. For example, if the next thing being loaded is going to be rendered in a helper app, not in the browser, the current page won't be unloaded and there should be no unload event at all.

Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55