title: Javascript detect browser close
body: <p>Is it possible to detect if the browser is closing in JavaScript? I tried using:</p>
  
  <pre><code>$( window ).unload(function() {
      //Code
  });
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>window.onbeforeunload = ExecuteMyCode;
  function ExecuteMyCode() {
      //Code
  }
  </code></pre>
  
  <p>But this both executes when we also click a link, button,... I ONLY  want to detect the browser close event.</p>