在別的地方看的,還沒研究
前端:遮蔽F12審查元素,禁止修改頁面程式碼
陳小釗的BLOG2018-05-28 13:58:185816收藏3 文章標籤:HTML前端 眾所周知,審查元素的情況下,大家都可以隨機更改一部分頁面的程式碼,注入惡意JS等等,這種情況避免也不難,雖然還能看到一部分H5原始碼,但是無法修改
一、遮蔽F12 審查元素
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;
}
}
除了遮蔽這個,我們還有其他有趣的設定:
二、遮蔽右鍵選單
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;
}
}
三、遮蔽貼上
document.onpaste = function (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;
}
}
四、遮蔽複製
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;
}
}
五、遮蔽剪下
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;
}
}
這種很適合小說網站,畢竟版權珍貴,被別人隨意copy走內容就不好了
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;
}
} ======================評論裡的==
-
-
(function() {
-
function R(a) {
-
let ona = "on" + a;
-
if (window.addEventListener){
-
window.addEventListener(a, function(e) {
-
for (let n = e.originalTarget; n; n = n.parentNode) n[ona] = null;
-
}, true);
-
}
-
window[ona] = null;
-
document[ona] = null;
-
if (document.body) document.body[ona] = null;
-
}
-
R("contextmenu");
-
R("click");
-
R("mousedown");
-
R("mouseup");
-
R("paste");
-
R("cut");
-
R("copy");
-
R("selectstart");
-
})()