文中用到了XMLHTTP.
function window_onbeforeunload(Projectnum)
{
if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altKey)
{
var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHTTP.open("POST","CheckProjectDeal.asp?Projectnum="+Projectnum,false);
oXMLHTTP.send();
Str=unescape(oXMLHTTP.responseText);
if (unescape(oXMLHTTP.responseText)!="YES")
{
window.event.returnValue="项目至少有一个销售机会,如离开,您所建的项目将不能保存!\n\n确认离开?";
}
}
}
function window_onunload(Projectnum)
{
if(event.clientX<=0 && event.clientY<0 || event.altKey)
{
if (Str!=@#YES@#)
{
if (form1.Mod.value != @#Save@# && form1.Mod.value != @#SaveNew@# )
{
var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
oXMLHTTP.open("POST","CheckProjectDeal.asp?Projectnum="+Projectnum+"&delproject=true",false);
oXMLHTTP.send();
}
}
}
}
<body>要按如下写。
<body bgcolor="#FFFFFF" text="#000000" onbeforeunload="window_onbeforeunload(@#<%=request("Projectnum")%>@#);" onUnload="window_onunload(@#<%=request("Projectnum")%>@#)">
文章来源于领测软件测试网 https://www.ltesting.net/