惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

拓源网

微信和QQ访问页面提示使用右上角浏览器打开 - 拓源网 批量替换文件名的powershell脚本 - 拓源网 使用Python移除PDF编辑权限密码 - 拓源网 写一款《PPT将指定页面另存为》小工具 - 拓源网 让jquery代码只能在指定域名下运行的三种方法 - 拓源网 PPT拼图批量生成工具 - 拓源网 Deepseek微信聊天机器人 - 拓源网 使用Python自动抓取zblog文章到腾讯云大模型知识引擎LKE,投喂数据专属化自己的知识库 - 拓源网 deepseek生图指令 - 拓源网
[反调试]审查元素清空页面或重定向 - 拓源网
2025-08-21 · via 拓源网

为防止用户通过浏览器审查元素代码,以保护网页内容的安全性和隐私性。以下是一个反调试示例代码,可以阻止用户通过审查元素查看网页源代码,变量为1时清空页面内容,变量为2时重定向到指定页面。

反调试脚本

function checkDevTools() {
    const threshold = 160;
    const devtoolsOpen = window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;
    if (devtoolsOpen) {
        /*
        *   debugprotect =
        *   1: 审查元素时->[清空页面内容]
        *   2: 审查元素时->[重定向到指定页面]
        */
        const debugprotect = '1';
        switch (debugprotect) {
            case '1':
                document.documentElement.parentNode.replaceChild(document.createElement('html'), document.documentElement);
                break;
            case '2':
                window.location.href = 'https://www.toyean.com/';
                break;
        }
    }
}
setInterval(checkDevTools, 100);

完整代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>[反调试]审查元素清空页面或重定向-拓源网</title>
    <script>
        function checkDevTools() {
            const threshold = 160;
            const devtoolsOpen = window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold;
            if (devtoolsOpen) {
                /*
                *   debugprotect =
                *   1: 审查元素时->[清空页面内容]
                *   2: 审查元素时->[重定向到指定页面]
                */
                const debugprotect = '1';
                switch (debugprotect) {
                    case '1':
                        document.documentElement.parentNode.replaceChild(document.createElement('html'), document.documentElement);
                        break;
                    case '2':
                        window.location.href = 'https://www.toyean.com/';
                        break;
                }
            }
        }
        setInterval(checkDevTools, 100);
    </script>
</head>
<body>
    <p>热爱可抵 岁月漫长!</p>
</body>
</html>

猛戳查看->演示效果

需要注意的是,反调试方法并非绝对可靠,一些高级用户仍可能绕过限制。

以下是绕过限制的方法介绍,和升级后的反调试代码,增加了performance检测、禁用鼠标右键、禁用选中文本、禁用复制文本、无限debugger、以及禁用调试快捷键等:

呜呼~~ 您需要有拓源网 VIP会员 账号,并且 登录 后即可查看或下载隐藏部分的内容.