我正在使用下面的JS,当用户点击“离开”或“停留在页面上”时,它会进行Ajax调用。我只希望在用户离开时触发它。
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**********************************************";
}
}