当前位置: 代码迷 >> 综合 >> 禁止开发者工具
  详细解决方案

禁止开发者工具

热度:2   发布时间:2024-02-23 13:22:50.0

 

// 禁止按钮F12
document.onkeydown = function (event) {var ev = event || window.event || arguments.callee.caller.arguments[0];console.log(event.keyCode)if (event.keyCode === 123) {return false; //123 代表F12键位}
}
// 禁止右键
document.oncontextmenu = function (e) {e.preventDefault();
};function checkDevTools(options) {const isFF = ~navigator.userAgent.indexOf("Firefox");let toTest = '';if (isFF) {toTest = /./;toTest.toString = function () {options.opened();}} else {toTest = new Image();toTest.__defineGetter__('id', function () {options.opened();});}setInterval(function () {options.offed();console.log(toTest);console.clear && console.clear();}, 1000);
}checkDevTools({opened: function () {// document.body.innerHTML = 'Dev Tools is on';window.location.href = 'about:blank'},offed: function () {// document.body.innerHTML = 'Dev Tools is off';}
});

 

  相关解决方案