title: Event to be triggered when leaving website or closes the browser
body: <p>I´m trying for a while execute a javascript function when a user leaves web site by typing a address in the browser and hits return or the user closes the brower clicking in the 'x' button.</p>
  
  <p>I tried the unload event but I cannot get the alert</p>
  
  <p>this is what I am doing:</p>
  
  <pre><code>$(window).unload(function () {
      alert("Are you sure?");
  });
  </code></pre>
  
  <p>also </p>
  
  <pre><code>$(body).unload(function () {
      alert("Are you sure?");
  });
  </code></pre>
  
  <p>I am running out of idea!</p>