0

I need to know if its possible to catch a user closing the browser window. I have tried using <body onbeforeunload="run_closeScripts()"> which works fine, but this is triggered on every postback! So its not much use if the user hits the refresh button or goes to another page.

Is there a reliable way to detect if its a full browser close rather than a postback?

<body onbeforeunload="run_closeScripts()">

<script type="text/javascript">

    function run_closeScripts() {

        //check if the browser is closing and not a postback
        window.alert("Your checkout will be removed!");
        window.location.replace("Exit.aspx");
    }
spender
  • 117,338
  • 33
  • 229
  • 351

1 Answers1

0

The only way to do this would be to use JavaScript and you can google for that, however, it is worth noting you CANNOT rely on the JavaScript running. Don't put stuff in you require to happen because you can't rely on it.

webnoob
  • 15,747
  • 13
  • 83
  • 165