用JS在IE和火狐下判断网页是刷新还是关闭
1个回答
展开全部
使用火狐判断刷新和关闭可以用下面这个,理论上应该是兼容IE的:
<!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="">
</HEAD>
<script type="text/javascript">
function close() //author: sunlei
{
var isIE=document.all?true:false;
if(isIE){//IE浏览器
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY<0 || window.event.altKey){
alert("是关闭而非刷新");
}else{
alert("是刷新而非关闭");
}
}
else{//火狐浏览器
if(document.documentElement.scrollWidth!=0)
alert("是刷新而非关闭");
else
alert("是关闭而非刷新");
}
}
</script>
<body onunload="close();">
</BODY>
</HTML>
<!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="">
</HEAD>
<script type="text/javascript">
function close() //author: sunlei
{
var isIE=document.all?true:false;
if(isIE){//IE浏览器
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if(b && window.event.clientY<0 || window.event.altKey){
alert("是关闭而非刷新");
}else{
alert("是刷新而非关闭");
}
}
else{//火狐浏览器
if(document.documentElement.scrollWidth!=0)
alert("是刷新而非关闭");
else
alert("是关闭而非刷新");
}
}
</script>
<body onunload="close();">
</BODY>
</HTML>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询