js禁用除錯臺,禁用開發者工具套餐
阿新 • • 發佈:2020-09-01
禁用所有快捷鍵 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(); });