title: How to find if user selected “Stay” or “Leave” button after beforeunload alert?
body: <p>I want to logout() user session when user leave website by closing web browser. I am using below code to display alert if user closes browser.</p>
  
  <p><strong>Code:-</strong></p>
  
  <pre><code>$(window).bind('beforeunload', function () {
      return '';
  });
  </code></pre>
  
  <p>Now I want to find whether use user have clicked "Leave this page" button or not. So that I can logout that user.</p>
  
  <p>I found some threads on Stack overflow, but none are useful on this scenario.</p>
  
  <p><a href="https://stackoverflow.com/questions/11271919/on-browser-close-beforeunload-how-to-find-if-user-selected-stay-or-leave?rq=1">On browser close beforeunload - how to find if user selected &quot;Stay&quot; or &quot;Leave&quot;</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18783535/jquery-beforeunload-when-closing-not-leaving-the-page">jquery beforeunload when closing (not leaving) the page?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page">javascript before leaving the page</a></p>