js监听刷新或关闭
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
function window.onbeforeunload()
{
//用户点击浏览器右上角关闭按钮
if(event.clientX>document.body.clientWidth&&event.clientY<0||event.altKey)
{
// document.getElementById("btnCompelete").click();
}
//用户点击任务栏,右键关闭
else if(event.clientY > document.body.clientHeight || event.altKey)
{
// document.getElementById("btnCompelete").click();
}
else//其他情况为刷新
{
alert("你在刷新");
}
}
</script>
</HEAD>
<body scroll="no" onbeforeunload="return CloseEvent();" onunload="UnLoadEvent()" >
</body>
<script language="JavaScript" type="text/javascript">
var DispClose = true;
function CloseEvent()
{
if (DispClose)
{
return "是否要刷新或离开";
}
}
function UnLoadEvent()
{
DispClose = false;
//在这里处理关闭页面前的动作
}
</script>
</HTML>