当前位置:首页 > 教程收藏 > 正文内容

禁止右键f12调试代码

fanren4年前 (2022-08-17)教程收藏149
//禁止鼠标右击
      document.oncontextmenu = function() {
        event.returnValue = false;
      };
      //禁用开发者工具F12
      document.onkeydown = document.onkeyup = document.onkeypress = function(event) {
        let e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 123) {
          e.returnValue = false;
          return false;
        }
      };
      let userAgent = navigator.userAgent;
      if (userAgent.indexOf("Firefox") > -1) {
        let checkStatus;
        let devtools = /./;
        devtools.toString = function() {
          checkStatus = "on";
        };
        setInterval(function() {
          checkStatus = "off";
          console.log(devtools);
          console.log(checkStatus);
          console.clear();
          if (checkStatus === "on") {
            let target = "";
            try {
              window.open("about:blank", (target = "_self"));
            } catch (err) {
              let a = document.createElement("button");
              a.onclick = function() {
                window.open("about:blank", (target = "_self"));
              };
              a.click();
            }
          }
        }, 200);
      } else {
        //禁用控制台
        let ConsoleManager = {
          onOpen: function() {
            alert("Console is opened");
          },
          onClose: function() {
            alert("Console is closed");
          },
          init: function() {
            let self = this;
            let x = document.createElement("div");
            let isOpening = false,
              isOpened = false;
            Object.defineProperty(x, "id", {
              get: function() {
                if (!isOpening) {
                  self.onOpen();
                  isOpening = true;
                }
                isOpened = true;
                return true;
              }
            });
            setInterval(function() {
              isOpened = false;
              console.info(x);
              console.clear();
              if (!isOpened && isOpening) {
                self.onClose();
                isOpening = false;
              }
            }, 200);
          }
        };
        ConsoleManager.onOpen = function() {
          //打开控制台,跳转
          let target = "";
          try {
            window.open("about:blank", (target = "_self"));
          } catch (err) {
            let a = document.createElement("button");
            a.onclick = function() {
              window.open("about:blank", (target = "_self"));
            };
            a.click();
          }
        };
        ConsoleManager.onClose = function() {
          alert("Console is closed!!!!!");
        };
        ConsoleManager.init();
      }


阳光的代码:

//屏蔽右键菜单
document.oncontextmenu = function (event) {
	if (window.event) {
		event = window.event;
	} try {
		var the = event.srcElement;
		if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
			return false;
		}
		return true;
	} catch (e) {
		return false;
	}
}//屏蔽剪切
document.oncut = function (event) {
	if (window.event) {
		event = window.event;
	} try {
		var the = event.srcElement;
		if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")) {
			return false;
		}
		return true;
	} catch (e) {
		return false;
	}
}//禁止f12
function fuckyou() {
	window.close(); //关闭当前窗口(防抽)
	window.location = "about:blank"; //将当前窗口跳转置空白页
}//禁止Ctrl+U
var arr = [123, 17, 18];
document.oncontextmenu = new Function("event.returnValue=false;"), //禁用右键
window.onkeydown = function (e) {
	var keyCode = e.keyCode || e.which || e.charCode;
    var ctrlKey = e.ctrlKey || e.metaKey;
    console.log(keyCode + "--" + keyCode);
    if (ctrlKey && keyCode == 85) {
		e.preventDefault();
    }
    if (arr.indexOf(keyCode) > -1) {
		e.preventDefault();
    }
}
function ck() {
	console.profile();
	console.profileEnd();
	//我们判断一下profiles里面有没有东西,如果有,肯定有人按F12了,没错!!
	if (console.clear) {
		console.clear()
	};
	if (typeof console.profiles == "object") {
		return console.profiles.length > 0;
	}
}
function hehe() {
	if ((window.console && (console.firebug || console.table && /firebug/i.test(console.table()))) || ( typeof opera == 'object' && typeof opera.postError == 'function' && console.profile.length > 0)) {
		fuckyou();
	}
	if (typeof console.profiles == "object" && console.profiles.length > 0) {
		fuckyou();
	}
}
hehe();
window.onresize = function () {
	if ((window.outerHeight - window.innerHeight) > 200)
    //判断当前窗口内页高度和窗口高度,如果差值大于200,那么呵呵
    fuckyou();
}
document.onkeydown = function (event) {
	if ((event.keyCode == 112) || //屏蔽 F1
		(event.keyCode == 113) || //屏蔽 F2
		(event.keyCode == 114) || //屏蔽 F3
		(event.keyCode == 115) || //屏蔽 F4
		// (event.keyCode == 116) || //屏蔽 F5
		(event.keyCode == 117) || //屏蔽 F6
		(event.keyCode == 118) || //屏蔽 F7
		(event.keyCode == 119) || //屏蔽 F8
		(event.keyCode == 120) || //屏蔽 F9
		(event.keyCode == 121) || //屏蔽 F10
		(event.keyCode == 122) || //屏蔽 F11
		(event.keyCode == 123)) { //屏蔽 F12
		return false;
	}
}
window.onhelp = function () {
	return false;
};
function forbidKeyboard() {
	$(document).keydown(function(e) {
		/*9:Tab键, 17:Control键, 18:Alt键, 123:F12键, 83:S键*/
		var keyboardCode = [9, 17, 18];
		for (i in keyboardCode) {
			if (keyboardCode[i] == e.keyCode) {
				return false;
			}
		}
		if ((e.keyCode == 83) && (e.ctrlKey || e.metaKey)) {
			return false;
		}
	});
	/*禁止文本选择功能*/
	$(document).bind("selectstart",function(){return false;});
}
$(function(){
	forbidKeyboard();
});
set 限制解除


“禁止右键f12调试代码” 的相关文章

Nginx的几个常用配置和技巧

一个站点配置多个域名server {     listen       80;     server_name  o...

rsync 用法教程

一、简介rsync 是一个常用的 Linux 应用程序,用于文件同步。它可以在本地计算机与远程计算机之间,或者两个本地目录之间同步文件(但不支持两台远程计算机之间的同步)。它也可以当作文件复制工具,替代cp和mv命令。它名称里面的r指的是 remote,rsync 其实就是"远程同步&qu...

【2023脚本收集】常用脚本备份

转自loc:https://hostloc.com/thread-1097221-1-2.html DD网络重装脚本PS:自定义密码直接 -p 你想要的密码就行!!!部分机器需要设置网卡,否则可以VNC,但是不能远程SSH-firmware        &n...

Linux reinstall:服务器系统一键重装脚本

转自loc:https://hostloc.com/thread-1094336-1-3.html项目地址,欢迎 star:https://github.com/leitbogioro/Tools萌咖的一键重装脚本近期经过更新,已经支持 Debian 11/Ubuntu 20.04 等新系统,加入了...

汉字正则表达式,简单匹配所有汉字的正则

一般情况下用不到匹配汉字的正则,但是/所以偶尔遇到的时候,每次都头大,\w会匹配英语和数字,而用双字节字符的编码匹配在有的环境下不成功:[\u4e00-\u9fa5]后来发现可以直接这样匹配中文:[一-龥]缺点是每次要记住并打出“龥”这个字,这比要我每次准确拼写对separate definitel...

redis清空缓存内容

有时候Wordpress开启redis缓存后会导致后天进不去跳转到首页的问题,排查下来原因可能是redis导致的,我们来手动清除一下redis对缓存教程开始ssh连接后 输入 redis-cli 进入redis,执行 flushall 出现OK这清除完成,然后输入 exit 退出即可。[root@V...

评论列表

fanren
fanren
3年前 (2022-10-30)

如果无法使用要把最后一行的 set 限制解除 删除

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。