title: Html popup when user wants to exit
body: <p>I have this javascript code which launches exit popup html code (div - #exitpopup_bg and #exitpopup) when user moves mouse out of the document. I want it to launch only when the user wants to leave the page (when the user wants to close the tab). Also I would like  to load both, my html code and browser alert at the same time. Any help would be highly appreciated. </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function() {
  var counter=0;
      $(document).mousemove(function(e) {
  
          $('#exitpopup').css('left', (window.innerWidth/2 - $('#exitpopup').width()/2));
          $('#exitpopup').css('top', (window.innerHeight/2 - $('#exitpopup').height()/2));
  
          if(counter ==0 &amp;&amp; e.clientY &lt;= 30)
  
  
          {
              // Show the exit popup
              $('#exitpopup_bg').fadeIn();
              $('#exitpopup').fadeIn();   
              counter++;
  }
  
  
  
      });
  
      $('#xmark').click(function(){
          $('#exitpopup_bg').fadeOut();
          $('#exitpopup').slideUp();
      }); 
  
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>So when user clicks x on the page tab I want to launch the alert and this </p>
  
  <pre><code> $('#exitpopup_bg').fadeIn();
   $('#exitpopup').fadeIn();  
  </code></pre>
  
  <p>You can see how it is currently working here: <a href="http://www.brzedijete.com/test/rezultatiFUe.php" rel="nofollow">http://www.brzedijete.com/test/rezultatiFUe.php</a> 
  Move the cursor the the top of the document and the message will pop up, that message needs to pop up only when the user wants to close the tab/page.  </p>