网页禁止审查及一些简单禁止用户对页面操作

前言

对于一些网页,如原创文章,我们不希望用户对我们的网页文章内容拷贝粘贴,所以前端可以做一些操作去禁止,但这种操作也只是防君子不防小人,上有政策下有对策,还是有方法破解的。

先说破解禁止 F12 方法

遇到有些网页禁止 F12 审查,我们可以用空白网页先开调试模式,再在地址栏输入网址进入网页

简单禁止 F12 审查

此方法就是 js 监听 F12 键盘事件去做操作(不安全,存在绕过漏洞)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
document.onkeydown = function() {
if (window.event && window.event.keyCode == 123) {
alert("F12被禁用");
event.keyCode = 0;
event.returnValue = false;
}
if (window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if (window.event && window.event.keyCode == 8) {
alert(str + "\n请使用Del键进行字符的删除操作!");
window.event.returnValue = false;
}
};

屏蔽右键菜单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
document.oncontextmenu = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (
!(
(the.tagName == "INPUT" && the.type.toLowerCase() == "text") ||
the.tagName == "TEXTAREA"
)
) {
return false;
}
return true;
} catch (e) {
return false;
}
};

屏蔽粘贴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
document.onpaste = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (
!(
(the.tagName == "INPUT" && the.type.toLowerCase() == "text") ||
the.tagName == "TEXTAREA"
)
) {
return false;
}
return true;
} catch (e) {
return false;
}
};

屏蔽复制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
document.oncopy = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (
!(
(the.tagName == "INPUT" && the.type.toLowerCase() == "text") ||
the.tagName == "TEXTAREA"
)
) {
return false;
}
return true;
} catch (e) {
return false;
}
};

屏蔽剪切

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
document.oncut = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (
!(
(the.tagName == "INPUT" && the.type.toLowerCase() == "text") ||
the.tagName == "TEXTAREA"
)
) {
return false;
}
return true;
} catch (e) {
return false;
}
};

屏蔽选中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
document.onselectstart = function(event) {
if (window.event) {
event = window.event;
}
try {
var the = event.srcElement;
if (
!(
(the.tagName == "INPUT" && the.type.toLowerCase() == "text") ||
the.tagName == "TEXTAREA"
)
) {
return false;
}
return true;
} catch (e) {
return false;
}
};

总结

凡事无绝对,没法做到真正禁止。浏览器菜单里查看页面源代码,直接ctrl+s,爬虫
对于页面安全性研究不深,代码来源网上寻找,用时自取。

Powered by Hexo and Hexo-theme-hiker

Copyright © 2018 - 2021 胡豪的博客 All Rights Reserved.

访客数 : | 访问量 :