title: run ajax request on browser closed
body: <p>I am working on a site and currently encounter a problem, i have a user who would be a rider when he comes to my website he must be marked active and when he leaves he must be mark in-active. Well i am able to mark him active and even in-active when he properly log out.
  But what if he close the browser or the tab. Secondly my web app will mostly be run on mobile phone so what if the rider switch between browser and some other app.
  I have already tried</p>
  
  <pre><code>window.onbeforeunload = function(event) {
          //My Ajax Request
  });
  
  window.addEventListener("unload", function(event) {
          //My Ajax Request
  });
  </code></pre>
  
  <p>but its work great on firefox but only work sometimes on chrome and internet explorer and is not reliable.</p>
  
  <p>I was hoping someone could guide me for any better and reliable approach.</p>