【JS】完全屏蔽F12和右键

开门见山

这是博主组合起来的代码,轻松屏蔽鼠标,F12,控制台快捷键,只要直接访问网页,简直无懈可击!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//屏蔽F12和右键
function click(e) {
if (document.all) {
if (event.button == 2 || event.button == 3) {
alert("屏蔽了,按也没用!");
oncontextmenu = 'return false';
}
}
if (document.layers) {
if (e.which == 3) {
oncontextmenu = 'return false';
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = click;
document.oncontextmenu = new Function("return false;")

document.onkeydown = document.onkeyup = document.onkeypress = function() {
if (window.event.keyCode == 123) {
window.event.returnValue = false;
return (false);
}
}
//禁用右键(防止右键查看源代码)
window.oncontextmenu = function() {
return false;
}
//禁止任何键盘敲击事件(防止F12和shift+ctrl+i调起开发者工具)
window.onkeydown = window.onkeyup = window.onkeypress = function() {
window.event.returnValue = false;
return false;
}
/*如果用户在工具栏调起开发者工具,那么判断浏览器的可视高度和可视宽度是否有改变,如有改变则关闭本页面
手机可能会误判,需要的话可删除注释。
var h = window.innerHeight, w = window.innerWidth;
window.onresize = function () {
if (h != window.innerHeight || w != window.innerWidth) {
window.close();
window.location = "404.html";
}
}
*/

【JS】完全屏蔽F12和右键
https://www.yuanzj.top/posts/3f4bfdfd.html
作者
yzl3014
发布于
2022年8月22日
许可协议