赵匡胤 发表于 2022-1-27 14:06:55

js禁用调试台,禁用开发者工具套餐

禁用所有快捷键   f12, ctrl禁止调试js文件打开调试台关闭页面
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
    // 判断是否按下F12,F12键码为123
    if (event.keyCode === 123 || event.ctrlKey) {
      event.preventDefault(); // 阻止默认事件行为
      window.event.returnValue = false;
      layer.msg("别看代码了= =")
    } else if (event.keyCode === 116) {
      if (navigator.userAgent.indexOf('MSIE') > 0) { // close IE
   if (navigator.userAgent.indexOf('MSIE 6.0') > 0) {
      window.opener = null;
      window.close();
   } else {
      window.open('', '_top');
      window.top.close();
   }
} else { // close chrome;It is effective when it is only one.
   window.opener = null;
   window.open('', '_self');
   window.close();
}
    }
}
window.oncontextmenu = function () {
    event.preventDefault(); // 阻止默认事件行为
    layer.msg("右键也不行哦")
    return false;

}
var threshold = 160; // 打开控制台的宽或高阈值
// 每秒检查一次
setInterval(function () {
    if (window.outerWidth - window.innerWidth > threshold ||
      window.outerHeight - window.innerHeight > threshold) {
      // 如果打开控制台,关闭页面
       if (navigator.userAgent.indexOf('MSIE') > 0) { // close IE
   if (navigator.userAgent.indexOf('MSIE 6.0') > 0) {
      window.opener = null;
      window.close();
   } else {
      window.open('', '_top');
      window.top.close();
   }
} else { // close chrome;It is effective when it is only one.
   window.opener = null;
   window.open('', '_self');
   window.close();
}
    }
}, 1000);
// 禁止用户调试js代码
function disableDebugger() {
    debugger;
}
$(document).ready(function () {
    disableDebugger();
});
页: [1]
查看完整版本: js禁用调试台,禁用开发者工具套餐