JavaScript判斷瀏覽器是關閉還是刷新,其實覺得沒有什么實用性,就算是作為Js學習的一個參考文檔吧。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Js智能判斷瀏覽器是關閉還是刷新</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
</head>
<body>
關閉或刷新瀏覽器試試!
<script language="javascript">
window.onbeforeunload=function(){
var n=window.event.screenX-window.screenLeft;
var b=n>document.documentElement.scrollWidth-20;
if(b&&window.event.clientY<0||window.event.altKey){
alert("關閉"); //25網(LieHuo41.Net)提示:僅在IE下有效
}else{
alert("刷新");
}
}
</script>
</body>
</html>