防止用户在浏览器中打开右键菜单、文本选中、复制内容、F12打开控制台的操作
右键菜单
document. = function (event) {
event.preventDefault();
};文本选中
if(document.all){
document. start= function(){return false;}; //for ie
}else{
document. = function(){return false;};
document. = function(){return true;};
}
document. start = new Function('event.returnValue=false;');-moz-user-select: none; -webkit-user-select: none; -ms-user-select: none; -khtml-user-select: none; user-select: none;
复制内容
document. = 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;
}
}F12打开控制台
document. = document. = document. = function(event) {
var e = event || window.event || arguments.callee.caller.arguments[0];
if (e && e.keyCode == 123) {
e.returnValue = false;
return (false);
}
}检测用户打开控制台后强制跳转
var ConsoleManager = {
onOpen: function() {
alert('Console is opened');
},
onClose: function() {
alert('Console is closed');
},
init: function() {
var self = this;
var x = document.createElement('div');
var isOpening = false,
isOpened = false;
.defineProperty(x, 'id', {
get: function() {
if (!isOpening) {
self.onOpen();
isOpening = true;
}
isOpened = true;
}
});
setInterval(function() {
isOpened = false;
console.info(x);
console.clear();
if (!isOpened && isOpening) {
self.onClose();
isOpening = false;
}
}, 200);
}
};
ConsoleManager.onOpen = function() {
//打开控制台,跳转到百度
try {
window.open('https://www.baidu.com/', (target = '_self'));
} catch (err) {
var a = document.createElement('button');
a. = function() {
window.open('https://www.baidu.com', (target = '_self'));
};
a.click();
}
};
ConsoleManager.onClose = function() {
alert('Console is closed!!!!!');
}; 继续阅读与本文标签相同的文章
下一篇 :
加入“公益宝贝”,一起守护亚洲象和长江江豚
-
企业数字化转型报告:四种类型企业与它们的数据运用现状
2026-05-22栏目: 教程
-
如何基于维度模型自动化生成SQL语句
2026-05-22栏目: 教程
-
阿里云新版人脸识别基于JAVA签名校验使用示例教程
2026-05-22栏目: 教程
-
mysql中的键和索引!
2026-05-22栏目: 教程
-
MySQL运行原理与基础架构!
2026-05-22栏目: 教程
