JS屏蔽鼠标右键审查元素,禁用键盘F12功能,或者其他键盘功能(详情如下)
屏蔽鼠标右键点击审查元素
HTML方法:body标签上面加属性
<body ondragstart="window.event.returnValue=false" oncontextmenu="window.event.returnValue=false" onselectstart="event.returnValue=false">
</body>
JS方法:
document.onkeydown = function(){
if(window.event && window.event.keyCode == 123) {
event.keyCode=0;
event.returnValue=false;
}
if(window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 8) {
window.event.returnValue=false;
}
}
禁用键盘F12事件,及其其他键盘事件(F1-F12,Ctrl+s,Ctrl+P)等:
document.onkeydown = function () {
if (window.event && window.event.keyCode == 123) {
event.keyCode = 0;
event.returnValue = false;
}
if (window.event && window.event.keyCode == 13) {
window.event.keyCode = 505;
}
// 禁止通过F12打开控制台
let e = event || window.event || arguments.callee.caller.arguments[0];
//禁用F1-F12
if (event.keyCode === 112) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 113) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 114) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 115) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 116) {
// event.preventDefault()
// event.returnValue = false
}
if (event.keyCode === 117) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 118) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 119) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 120) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 121) {
event.preventDefault()
event.returnValue = false
}
if (event.keyCode === 122) {
// event.preventDefault()
// event.returnValue = false
}
if (event.keyCode === 123) {
event.preventDefault()
event.returnValue = false
}
}
还没有评论,快来发表第一个评论吧