title: Browser/tab close detection using Javascript (or any other language)
body: <p>I searched for this question in various places, but all that they mention is the use of Javascript <code>window.unload</code> and <code>window.onbeforeunload</code>. Also it doesn't work in Chrome most of the times as it gets blocked.</p>
  <p>Then how does google manage to do it. If we are composing a mail and by mistake close the tab, google prompts us by a &quot;Are you sure?&quot; box.</p>
  <p>Can somebody help me out?</p>
  <p><b>What actually I want to do is to ask confirmation of the user, when he is filling in the form and by mistake clicks on tab close. If yes, I allow him to navigate away else he stays on the page &amp; continues to fill his form.</b></p>