下面是MSDN的代码,你可以在closeIt里面再做自己的处理。<HTML> <HEAD> <SCRIPT> function closeIt() { event.returnValue = "Any string value here forces a dialog box to \ appear before closing the window."; } </SCRIPT> </HEAD> <BODY onbeforeunload="closeIt()"> <a href="http://www.microsoft.com">Click here to navigate to www.microsoft.com</a> </BODY> </HTML>
function closeFun() { if(event.clientY<0||event.altKey==true) { var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlHttp.open("get","OnClose.aspx",false); xmlHttp.send(null); } } window.onbeforeunload=closeFun;
function close() { //............ } 如上,先把写好的JS函数close()传到客户端,由<BODY onbeforeunload="close()">关闭页面前调用close()
<HEAD>
<SCRIPT>
function closeIt()
{
event.returnValue = "Any string value here forces a dialog box to \
appear before closing the window.";
}
</SCRIPT>
</HEAD>
<BODY onbeforeunload="closeIt()">
<a href="http://www.microsoft.com">Click here to navigate to
www.microsoft.com</a>
</BODY>
</HTML>
{
if(event.clientY<0||event.altKey==true)
{
var xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("get","OnClose.aspx",false);
xmlHttp.send(null);
}
}
window.onbeforeunload=closeFun;
{
//............
}
如上,先把写好的JS函数close()传到客户端,由<BODY onbeforeunload="close()">关闭页面前调用close()