HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法;原创
原创禁止使用鼠标右键,禁止全选、复制、粘贴;
oncontextmenu事件禁用右击菜单;
js代码:
document.oncontextmenu = function(){
event.returnValue = false;
}
// 或者直接返回整个事件。。。
document.oncontextmenu = function(){
return false;
}
onselectstart事件禁用在网页上选择的内容;
js代码:
document.onselectstart = function(){
event.returnValue = false;
}
// 或者直接返回整个事件。。。
document.onselectstart = function(){
return false;
}
oncopy事件禁用复制;
js代码:
document.oncopy = function(){
event.returnValue = false;
}
// 或者直接返回整个事件。。。
document.oncopy = function(){
return false;
}
如果您只想简单地禁用鼠标右键并复制粘贴上述三个事件,也可以直接编写它们HTML中的body上面;
禁用鼠标事件
document.onmousedown = function(e){
if ( e.which == 2 ){// 按下鼠标滚轮,滚动不会触发
return false;
}
if( e.which==3 ){// 鼠标右键
return false;
}
}
禁用键盘ctrl、alt、shift
document.onkeydown = function(){
if( event.ctrlKey ){
return false;
}
if ( event.altKey ){
return false;
}
if ( event.shiftKey ){
return false;
}
}
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除