- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <HTML>
- <HEAD>
- <TITLE> javascript 双击取消html 页面 右键、选择文本 禁用 限制 </TITLE>
- </HEAD>
- <BODY
- oncontextmenu="self.event.returnValue=false"
- onselectstart="return false" ondblclick="func1()">
- javascript 双击取消html 页面 右键、选择文本 禁用 限制
- hyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy8888888888888888888888888
- <script>
- function func1(){
- //alert("x");
- //window.document.oncontextmenu = function(){ };
- //alert(window.document.oncontextmenu);
- window.document.oncontextmenu = function(){ self.event.returnValue=true;}//默认为 null;
- window.document.onselectstart = function(){ return true;}
- }
- </script>
- </BODY>
- </HTML>
- <pre class="html" name="code">function click(e) {
- if (document.all) {
- if (event.button==1||event.button==2||event.button==3) {
- oncontextmenu='return false';
- }
- }
- if (document.layers) {
- if (e.which == 3) {
- oncontextmenu='return false';
- }
- }
- }
- if (document.layers) {
- document.captureEvents(Event.MOUSEDOWN);
- }
- document.onmousedown=click;
- document.oncontextmenu = new Function("return false;")
- var travel=true
- var hotkey=17 /* hotkey即为热键的键值,是ASII码,这里99代表c键 */
- if (document.layers)
- document.captureEvents(Event.KEYDOWN)
- function gogo(e)
- { if (document.layers) {
- if (e.which==hotkey&&travel){
- alert("操作错误.或许是您按错了按键!"); } }
- else if (document.all){
- if (event.keyCode==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); }}
- }
- document.onkeydown=gogo
- 把上面的代码另存为一个JS文件,然后在想实现此效果的页面调用即可!
- ===================================================
- 把下列代码放到<body></body>或者<head></head>之间
- <script LANGUAGE="JavaScript">
- function click() { if (event.button==2)
- {alert('你好,右键已被禁止使用'); } } document.onmousedown=click
- </script>
- ===================================================
- 禁止点击鼠标右键1:
- <SCRIPT language=JavaScript>
- <!--
- file://锁鼠标右键和键盘CONTEXTMENU键
- function click(e) {
- if (document.all) {
- if (event.button==2||event.button==3) { alert("欢迎光临寒舍,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!");
- oncontextmenu='return false';
- }
- }
- if (document.layers) {
- if (e.which == 3) {
- oncontextmenu='return false';
- }
- }
- }
- if (document.layers) {
- document.captureEvents(Event.MOUSEDOWN);
- }
- document.onmousedown=click;
- document.oncontextmenu = new Function("return false;")
- // -->
- </SCRIPT>
- 二、禁止点击鼠标右键2:
- <!--将以下代码加入HTML的<HEAD></HEAD>之间-->
- <script language="javascript">
- function click() {
- if (event.button==2) {
- alert('欢迎光临寒舍,有什么需要帮忙的话,请与站长联系!谢谢您的合作!!!')
- }
- }
- document.onmousedown=click
- </script>
- 三、禁止鼠标右键3(推荐):
- <script language="JavaScript" type="text/JavaScript">
- <!--
- function MM_reloadPage(init) { //reloads the window if Nav4 resized
- if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
- document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
- else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
- }
- MM_reloadPage(true);
- //-->
- </script>
- </head>
- <body leftmargin=0 topmargin=0 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()">
- <noscript><iframe src=*></iframe></noscript> </pre>