用JS在IE和火狐下判断网页是刷新还是关闭

    技术2026-06-14  13

    在网上找的,做这方面的东西实在痛苦,希望有天浏览器可以统一

    <script type="text/javas 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> unload="close();">

    下面这个可直接放js文件中:

    //捕获浏览器关闭 function window.onbeforeunload(){    var n = window.event.screenX - window.screenLeft;         var b = n > document.documentElement.scrollWidth-20;         if(b && window.event.clientY<0 || window.event.altKey){         alert("该用户已强制退出登录!!");         var ur = convertURL("RemoveUserOnline");             $.ajax( {     url :ur,     cache :false,     success : function(html) {     }    });         }else{             //alert("是刷新而非关闭");         } }

     本文用 菊子曰发布
    最新回复(0)