Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have written a code in javascript ASP.net to do some logic on browser close, i.e., on 'onbeforeunload' event. The code is running pretty fine. But it gets executed on page refresh also. I want the code to be run on browser close only and not on refresh. Below is the jasvascript code that I have written. Can u please help me in the same.......

JavaScript
<script type ="text/javascript">

    window.onbeforeunload = function () {
        if ((window.event.clientX < 0) || (window.event.clientY < 0) || window.event.clientY < -80) {
            var sessionvalue = '<%= Session["UserID"] %>';

            EndSession.saveLogOutTime("Jayanti");
        }
    }
</script>
Posted

1 solution


You can't. A page refresh is like navigating away and unloading the DOM so the onbeforeunload event will always be called.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900