当前位置:网站首页>谈谈基于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()

后记
边栏推荐
- 房地产数字化转型方案:全方位数智化系统运营,助力房企管控实效提升
- Joint search set
- 第四步-用户开发环境设置
- 高温天气筑牢安全生产防线,广州海珠区开展加油站应急演练
- ELK实时日志分析平台
- 每天在岗不足8小时被辞?腾讯前员工追讨1300万加班费等,法院终审获赔9万
- In the era of home health diagnosis, Senzo creates enhanced lateral flow test products
- In php7?? And?: Differences between
- Espresso systems, which has just obtained financing, has both intellectual property rights and team ethics in trouble
- 选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步
猜你喜欢

图解 3 种主流企业架构模式(建议收藏!)

Basic examples that must be mastered by beginners of C #

On July 13, 2021, we collapsed like this
![[learning notes] border and period](/img/a4/5493f7eefc7dd0e38bc9a53a92b87b.png)
[learning notes] border and period

Pycharm uses CONDA to call the remote server

How to get more marks in the game under the new economic model of Plato farm

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

Boss: there are too many systems in the company. Can we realize account interworking?

2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了

19. 删除链表的倒数第 N 个结点
随机推荐
Sizebasedtriggingpolicy introduction
Judge whether the string is palindrome
10分钟快速入门EVS【玩转华为云】
LinkedList source massage, ah comfortable
The high temperature continues, and public transport enterprises carry out special safety training
【Gradle】This version of the JMH Gradle plugin requires Gradle 6+, you are using 6.6.
(十)defer关键字
Pycharm uses CONDA to call the remote server
Seektiger eco pass STI new progress, log in to ZB on April 14
2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
[ESP32][esp-idf] esp32s3快速搭建LVGLV7.9
Redis interview questions must be known and learned
PHP7 中 ?? 与? :的区别
redis的基础知识
Joint search set
ES(8.1)认证题目
13 probability distributions that must be understood in deep learning
Introduction to thresholdfilter
【FPGA教程案例41】图像案例1——通过verilog读取图片
pkg打包node工程