当前位置:网站首页>谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
2022-07-28 09:56:00 【InfoQ】
前言
- F12
- 右键==》检查
- 浏览器==》更多工具==》开发者工具(快捷键:ctrl+shift+i)
阻止打开控制台
阻止F12事件
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
// 判断是否按下F12,F12键码为123
if (event.keyCode = 123) {
event.preventDefault() // 阻止默认事件行为
window.event.returnValue = false
}
}

阻止右键事件
oncontextmenuwindow.oncontextmenu = function() {
event.preventDefault() // 阻止默认事件行为
return false
}

JS操作控制台
浏览器==》更多工具==》开发者工具(快捷键:ctrl+shift+i)定时检查浏览器窗口变化
let threshold = 160 // 打开控制台的宽或高阈值
window.setInterval(function() {
if (window.outerWidth - window.innerWidth > threshold ||
window.outerHeight - window.innerHeight > threshold) {
// 如果打开控制台,则刷新页面
window.location.reload()
}
}, 1000)

打开控制台弹窗,启用调试debug调试
debuggerdebuggerdebugger第一种debug调试
setInterval(function() {
check()
}, 1000);
var check = function() {
function doCheck(a) {
if (("" + a / a)["length"] !== 1 || a % 20 === 0) {
(function() {}
["constructor"]("debugger")())
} else {
(function() {}
["constructor"]("debugger")())
}
doCheck(++a)
}
try {
doCheck(0)
} catch (err) {}
};
check();

第二种debug调试
if(window.location.href.indexOf('#debug')==-1){
setInterval(function(){
(function (a) {return (function (a) {return (Function('Function(arguments[0]+"' + a + '")()'))})(a)})('bugger')('de', 0, 0, (0, 0))
}, 1000)
}

打开控制台提示(可实现跳转url或刷新)
function toDevtools(){
let num = 0
var devtools = new Date()
devtools.toString = function() {
num++;
if(num>0){
alert('控制台打开了')
// 可以写刷新或者跳转的逻辑
}
}
console.log(devtools);
}
toDevtools()

后记
边栏推荐
- In retaliation for the dismissal of the company, I changed all code comments of the project!
- Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
- Kubernetes
- (10) Defer keyword
- (十)defer关键字
- 为什么要考一级建造师,一建证书含金量有多高?
- Function introduction and description of @jsontype annotation in fastjson
- Mobile number, fixed line regular expression
- 广州地铁14号线新市墟站开建,白云区居民即将开启双线换乘模式!
- 建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
猜你喜欢

二分、三分、01分数规划 【第I弹】

我用小程序容器让移动研发效率提升了5倍!

Data can't lie. Plato farm is the leader of the meta universe

Weekly report on July 27, 2022

Xiao Hei stands up again and looks at leetcode:653. Sum of two IV - enter BST

并查集

In hot weather, the line of defense for safe production was strengthened, and Guangzhou Haizhu District carried out emergency drills for gas stations

Redis面试题必知必会

高温持续,公交企业开展安全专项培训

office2013以上输入数学公式
随机推荐
选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步
_HUGE and __IMP__HUGE in “math.h“
How to get more marks in the game under the new economic model of Plato farm
Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
1. 两数之和
【学习笔记】border与period
Etcd(高可用KV数据库)
Arthas tutorial
(10) Defer keyword
On July 13, 2021, we collapsed like this
Experiment 4 uses fdisk to manage hard disk
ES (8.1) certification topic
PHP Basics
LinkedList源码按摩,啊舒服
Basic examples that must be mastered by beginners of C #
(十)defer关键字
web之圣杯和双飞翼布局、float、clear、both
Introduction to consoleappender
Extreme deflation and perpetual motion machine model will promote the outbreak of platofarm
PHP 常用的数组整理