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

禁止右键f12调试代码

fanren3年前 (2022-08-17)教程收藏145
//禁止鼠标右击
      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调试代码” 的相关文章

宝塔面板离线降级版本步骤

宝塔面板离线降级版本步骤cd /root && wget http://download.bt.cn/install/update/LinuxPanel-7.4.5.zip unzip LinuxPanel-7.4.5.zip c...

【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 等新系统,加入了...

常用正则表达式(持续更新!)

识别ip地址的正则:(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])识别ip地址和端口号的正则:(([0-9]|[1-9][0-9]|1[0-...

linux挂载磁盘分区步骤

在进行操作之前,一定要先做好快照,不然配置文件写错了会导致服务器无法启动,救起来特别麻烦一、Centos的操作这篇文章主要介绍了linux如何永久挂载新硬盘和/etc/fstab配置文件的说明,磁盘格式化,磁盘管理、挂载新硬盘(linux运维基础)。首先列出文件系统的整体磁盘空间使用情况。可以用来查...

Linux配置静态ip地址

cenots配置静态ip:编辑网卡配置文件:vim /etc/sysconfig/network-scripts/ifcfg-ens33  #ifcfg-ens33为网卡名称BOOTPROTO=DHCP    #DHCP修改为st...

评论列表

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

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

发表评论

访客

看不清,换一张

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