[HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法]

[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上面;
<body oncontextmenu = "return false" ></body><body onselectstart = "return false" ></body><body oncopy = "return false" ></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; }}关键就在

oncontextmenu='return false'  ondragstart='return false'   onselectstart ='return false'   onselect='document.selection.empty()'   oncopy='document.selection.empty()'   onbeforecopy='return false'   onmouseup='document.selection.empty()'
一个更简单的方法就是在<body>中加入如下的代码,这样鼠标的左右键都失效了. topmargin="0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()" 1.禁止网页另存为:在<body>后面加入以下代码: <noscript> <iframe src="*.htm"></iframe> </noscript> 2.禁止网页内容复制.粘贴:在<body>中加入以下代码: <body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

转自:(http://www.cnblogs.com/happiness-mumu/p/6269465.html)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放...
    孤魂草阅读 915评论 0 0
  • 单例模式 适用场景:可能会在场景中使用到对象,但只有一个实例,加载时并不主动创建,需要时才创建 最常见的单例模式,...
    Obeing阅读 2,112评论 1 10
  • 个人博客:https://yeaseonzhang.github.io 花了半个多月的时间,终于又把“JS红宝书”...
    Yeaseon阅读 1,790评论 2 23
  • 数组: 下面创建一个数组,用于存储5个人的数学成绩。 var myarray=new Array();//创建一个...
    无极之刃阅读 384评论 0 0