0

Hi Guys I am using the onbeforeunload method. But it fires when the user is actually navigating to any other page by clicking any link in the website/refreshing the Page which is not needed. I just need to find only when user closes the browser but not navigate or refresh the Page etc.. Isn't there . Thank you

     <script type="text/javascript">
          window.onbeforeunload = function (e) {
               var e = e || window.event;
               if (e) e.returnValue = 'Browser is being closed, is it okay?';//for IE & Firefox
               return 'Browser is being closed, is it okay?';// for Safari and Chrome
           };
        </script>
1

1 Answer 1

1

This would be impossible for the server to detect as the html is sent to the client and there isn't any active socket. A work around for this would be to make a socket with the user who is visiting your webpage, and when this socket is closed, you can assume the user has closed the page. But even then you can't detect a user closing a browser window.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.