-->

WEB资讯

您的当前位置:首页 > 资讯 > JS

网页屏蔽f12,屏蔽右键,屏蔽选中,屏蔽复制粘贴

2019-03-19 11:03:37  来源:admin 点击:1054

//屏蔽右键菜单
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){
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.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;
}
}
//屏蔽选中
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;
}
}

但是上面可以F12审查元素喔  所以下面提供了一段禁用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;
   }

}

不过上面的情况啊,在ie浏览器不支持,如果在狠点,那就别支持ie8以下的浏览器,那样怎么都打不开了,当然高手排除在外

相关文章更多 >

© 2024版权所有 水水网

电话:171780793