title: Ending a session on browser close only
body: <p>I'm trying to end a user's session when they close the browser,
  because they never logout properly.</p>
  
  <p>I need to change a value in the db after they close the browser only.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      window.onbeforeunload = check;
      function check() {
          return "Are you sure you want to exit this page?";
          //or put whatever function you need to call when a user closes the web //browser.
          endSession();
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>This does work on closing the browser but unfornately also when I redirect to any other page.</p>
  
  <p>Is there any way to do this for browser close only?</p>
  
  <p>Grant.</p>