欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」JS禁止鼠标右键/禁止选择/禁止复制/禁止粘贴/禁止ctrl/禁止alt/禁止shift/禁止F12的方法

作者 : 自学哈 本文共1680个字,预计阅读时间需要5分钟 2023-01-13 共177人阅读
也想出现在这里? 联系我们

禁用右键菜单
oncontextmenu事件禁用右键菜单

document.oncontextmenu = function(){
	event.returnValue = false;
}
//或者直接返回整个事件
document.oncontextmenu = function(){
    return false;
}

或者:body中加入如下的代码,鼠标的左右键都失效

topmargin="0" 
οncοntextmenu="return false" οndragstart="return false" onselectstart 
="return false" οnselect="document.selection.empty()" 
οncοpy="document.selection.empty()" onbeforecopy="return false" 
οnmοuseup="document.selection.empty()" 

禁用选取内容
onselectstart事件禁用网页上选取的内容

document.onselectstart = function(){
	event.returnValue = false;
}
//或者直接返回整个事件
document.onselectstart = function(){
   return false;
}

禁用复制
oncopy事件禁用复制

document.oncopy = function(){
    event.returnValue = false;
}
// 或者直接返回整个事件
document.oncopy = function(){
    return false;
}

以上三种事件,如果只想单纯的禁用鼠标右键,和复制粘贴,还可以将它们直接写到HTML中的body上面

<body oncontextmenu = "return false" ></body>
<body onselectstart = "return false" ></body>
<body oncopy = "return false" ></body>

或者:禁止网页内容复制.粘贴:在body中加入以下代码

<body
 οnmοusemοve=/HideMenu()/ οncοntextmenu="return false" 
οndragstart="return false" onselectstart ="return false" 
οnselect="document.selection.empty()" 
οncοpy="document.selection.empty()" onbeforecopy="return false" 
οnmοuseup="document.selection.empty()">

禁用鼠标事件

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;
    }
}

禁用F12事件

/*document.oncontextmenu = function(){return false;}*/
document.onkeydown=function (e){
    var currKey=0,evt=e||window.event;
    currKey=evt.keyCode||evt.which||evt.charCode;
    if (currKey == 123) {
        window.event.cancelBubble = true;
        window.event.returnValue = false;
    }
}

禁止网页另存为
在body后面加入以下代码

<noscript> 
	<iframe src="*.htm"></iframe> 
</noscript> 

 

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」JS禁止鼠标右键/禁止选择/禁止复制/禁止粘贴/禁止ctrl/禁止alt/禁止shift/禁止F12的方法
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号