js判断页面是刷新还是关闭 (兼容FF。IE)

来源:互联网 发布:电视软件安装 编辑:程序博客网 时间:2024/05/21 10:53

  • <script type="text/javascript"><!--  
  •         function close(evt) //author: sunlei  
  •         {      
  •             var isIE=document.all?true:false;  
  •             evt = evt ? evt :(window.event ? window.event : null);  
  •             if(isIE){//IE浏览器  
  •                 var n = evt.screenX - window.screenLeft;  
  •                 var b = n > document.documentElement.scrollWidth-20;  
  •                 if(b && evt.clientY<0 || evt.altKey){  
  •                     //alert("是关闭而非刷新");  
  •                     window.location.href="../include/logout.php";  
  •                 }  
  •                 else{  
  •                     //alert("是刷新而非关闭");  
  •                     return false;  
  •                 }  
  •             }  
  •             else{//火狐浏览器  
  •                 if(document.documentElement.scrollWidth!=0)  
  •                 {  
  •                     //alert("是刷新而非关闭");  
  •                     //window.location.href="http://ayue05.blog.163.com/blog/report_list.php?ss=1";  
  •                     return false;  
  •                       
  •                 }  
  •                 else{  
  •                     alert("是关闭而非刷新");  
  •                     //window.location.href="http://ayue05.blog.163.com/blog/repost_list.php?ss=0";  
  •                     //alert("bbbbbbb");  
  •                 }  
  •             }  
  •         }  
  • // --></script>
  • <BODY onunload="close(event);">
  • 0 0
    原创粉丝点击