I'm using the JS below and it's making an Ajax call when the user clicks either to Leave or Stay on the page. I only want it to fire when the user leaves.
window.onbeforeunload = function()
{
if(document.getElementById("SelectionsUnsaved").value=="Yes")
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","AjaxCallHere.asp" ,false);
xmlhttp.onreadystatechange=function()
{
}
xmlhttp.send();
return "**************** WARNING ****************\n\n YOU HAVE NOT SAVED ANY TIPS !!\n\n**********************************************";
}
}