网页防审查源码

直接上代码

document.onkeydown = function(){
      if(window.event && window.event.keyCode == 123) {
          alert("F12被禁用");
          event.keyCode=0;
          event.returnValue=false;
      }
      if(window.event && window.event.keyCode == 13) {
          window.event.keyCode = 505;
      }
      if(window.event && window.event.keyCode == 8) {
          alert(str+"\n请使用Del键进行字符的删除操作!");
          window.event.returnValue=false;
      }
  }
  // 为右键添加自定义事件,可以禁用  
  window.oncontextmenu = function() {  
      event.preventDefault(); // 阻止默认事件行为  
      return false;  
  }  
  //禁用预先调试和控制台开发者工具
  var threshold = 160; // 打开控制台的宽或高阈值  
  // 每秒检查一次  
  window.setInterval(function() {  
      if (window.outerWidth - window.innerWidth > threshold ||   
      window.outerHeight - window.innerHeight > threshold) {  
          // window.close();//关闭页面
        CloseWebPage();
      }  
  }, 1e3); 
  function CloseWebPage() {     
    if (navigator.userAgent.indexOf("MSIE") > 0) {     
        if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {     
            window.opener = null;
            window.location.href="about:blank"; 
            window.close();     
        }     
        else {     
            window.open('', '_top'); 
            window.location.href="about:blank";
            window.top.close();     
        }     
    }     
    else if (navigator.userAgent.indexOf("Firefox") > 0) {     
        window.location.href = 'about:blank '; //火狐默认状态非window.open的页面window.close是无效的    
        //window.history.go(-2);     
    }     
    else {     
        window.opener = null;      
        window.open('', '_self', '');   
        window.location.href="about:blank";  
        window.close();     
    }     
  }     

猜你喜欢

转载自www.cnblogs.com/jianxian/p/8965015.html
今日推荐