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.
<script type="text/javascript">
$(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 && e.clientY <= 30)
{
// Show the exit popup
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
counter++;
}
});
$('#xmark').click(function(){
$('#exitpopup_bg').fadeOut();
$('#exitpopup').slideUp();
});
});
</script>
So when user clicks x on the page tab I want to launch the alert and this
$('#exitpopup_bg').fadeIn();
$('#exitpopup').fadeIn();
You can see how it is currently working here: http://www.brzedijete.com/test/rezultatiFUe.php 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.