JS实现禁止鼠标右键

来源:互联网 发布:集合java 编辑:程序博客网 时间:2024/06/09 17:10

 

比较全面的禁止鼠标右键的方法:

 

<script language="JavaScript"><!--if (window.Event) document.captureEvents(Event.MOUSEUP);function nocontextmenu(){event.cancelBubble = trueevent.returnValue = false;return false;}function norightclick(e){if (window.Event){ if (e.which == 2 || e.which == 3) return false;}else if (event.button == 2 || event.button == 3) { event.cancelBubble = true event.returnValue = false; return false; }}document.oncontextmenu = nocontextmenu; // for IE5+document.onmousedown = norightclick; // for all others//--></script>


 

禁止选择文本

 

<script type="text/javascript">var omitformtags=["input", "textarea", "select"]omitformtagsomitformtags=omitformtags.join("|")function disableselect(e){if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)return false}function reEnable(){return true}if (typeof document.onselectstart!="undefined")document.onselectstart=new Function ("return false")else{document.onmousedown=disableselectdocument.onmouseup=reEnable}</script>


 

文章转载自:  禁止鼠标右键的JS代码      http://www.studyofnet.com/news/198.html

 

原创粉丝点击