【www.gdgbn.com--浏览器】

文章从网上搜索了三款js判断浏览器关闭哦,他们可以判断用户是关闭浏览呢,还是刷新浏览器,这都利用到了js onload unonload 等一些怪方法哦。




js判断浏览器关闭
<script>
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)   
 {   
 //window.event.returnvalue = "1111";      
 userbasedao.upislogin(${adminbean.id});
 }    
}    


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("是关闭而非刷新");

window.open(this.location);  


//return false;

//window.event.returnvalue = ""; }

} else{

alert("是刷新而非关闭");

}

}

 


function promptonclose(e){

//e = e ? e : windowevent;

var promptstring = "你是否要离开此页面,离开该页面的信息将不被保存!";

//event.returnvalue = promptstring;

return promptstring;

}

if (window != top){

top.location.href = "www.baidu.com";

}else{

if (window.event) {

      window.onbeforeunload = function(event) {

     return promptonclose(event);

      }

} else {

      window.onbeforeunload = function() {

       return promptonclose(event);

        }

     }

}

 

</script>

方法三

function closeo教程pen(event) {
         if(event.clientx<=0 || event.clienty<0) {
             //获取当前时间
           var date=new date();
           //将date设置为过去的时间
           alert("关闭网页");
           date.settime(date.gettime()-10000);
           //将userid这个cookie删除
           document.cookie="zhuangtao;expire="+date.toutcstring();
           document.cookie="quanxianzifucuan;expire="+date.toutcstring();
           document.cookie="quanxian;expire="+date.toutcstring();
          s0 += "关闭窗口!"; sw = 1;
            onbeforeunload();
           // window.event.returnvalue = "关闭浏览器将退出系统.";
         }
         else
         {
                alert("刷新或离开");
         }
  }
             
                var currentkeycode = -1;

    function document.onkeydown() { // 本窗口的所有下属页面都必须含有本函数

       top.currentkeycode = event.keycode;
    }

    function onbeforeunload(){
   
     var sw = 0, s0 = "";
        if (currentkeycode == 116)
        {
           s0 += "刷新窗口!(f5)";
        }
        else
        {
           if ((event.altkey)&&(currentkeycode == 115))
            {
                  s0 += "关闭窗口!(alt+f4)"; sw = 1;
                   //获取当前时间
                   var date=new date();
                   //将date设置为过去的时间
                  alert("关闭窗口");
                   date.settime(date.gettime()-10000);
                   //将userid这个cookie删除
                   document.cookie="zhuangtao;expire="+date.toutcstring();
                   document.cookie="quanxianzifucuan;expire="+date.toutcstring();
                   document.cookie="quanxian;expire="+date.toutcstring();
            }
            else
            {
               if ((event.clientx > 0)&&(event.clientx < document.body.clientwidth))
               {
                  s0 += "刷新窗口!";
               }
               else
               {
                //获取当前时间
                   var date=new date();
                   //将date设置为过去的时间
                   alert("关闭网页");
                   date.settime(date.gettime()-10000);
                   //将userid这个cookie删除
                   document.cookie="zhuangtao;expire="+date.toutcstring();
                   document.cookie="quanxianzifucuan;expire="+date.toutcstring();
                   document.cookie="quanxian;expire="+date.toutcstring();
                  s0 += "关闭窗口!"; sw = 1;
               }
            }
        }
        if (sw == 1)
        {
          event.returnvalue = "";
        }
        else
        {
          currentkeycode = -1;
        }
   
    }




本文来源:http://www.gdgbn.com/bangongshuma/27632/