javascript 禁止右键,禁止复制,禁止粘贴
2011-11-06 13:47
501 查看
|
有时自己辛苦半天做的网页,尤其是一些javascript特效,很容易被人利用查看源文件而复制。那么如何才能防止被人查看源代码呢?我们可以利用event.button特性来做到。下表是event.button属性的可能取值及含义: 0 没按键 1 按左键 2 按右键 3 按左和右键 4 按中间键 5 按左和中间键 6 按右和中间键 7 按所有的键 参照上表,我们可以在<body>和</body>之间加入如下语句: <script type="text/javascript"> function Click(){ if (event.button!=1){alert('XXXXXXX');} document.onmousedown=Click; </script> <script type="text/javascript"> //以下为禁止鼠标右键的代码,不想禁止的可以删除 <!-- if (window.Event) document.captureEvents(Event.MOUSEUP); function nocontextmenu() { event.cancelBubble = true event.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) {alert(" xxxxxxxxxxx"); } } { 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 clickmessage="本站图片禁用右键!" function disableclick(e) { if (document.all) { if (event.button==2||event.button==3) { if (event.srcElement.tagName=="IMG"){ alert(clickmessage); return false; } } } if (document.layers) { if (e.which == 2) { alert(clickmessage); return false; } } } function associateimages(){ for(i=0;i<document.images.length;i++) document.images[i].onmousedown=disableclick; } if (document.all) document.onmousedown=disableclick else if (document.layers) associateimages() </script> 功能:禁止右键、禁选择、禁粘贴、禁shift、禁ctrl、禁alt <script language="JavaScript"> <!-- function key(){ //禁止Shift if(event.shiftKey){ window.close();} //禁止Alt if(event.altKey){ window.close();} //禁止Ctrl if(event.ctrlKey){ window.close();} return false;} document.onkeydown=key; if (window.Event) document.captureEvents(Event.MOUSEUP); function nocontextmenu(){ event.cancelBubble = true event.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> <body onselectstart="return false"; onpaste="return false";> 如何用用javascript 禁止右键,禁止复制,禁止粘贴,做站时常会用到这些代码: 1. <body oncontextmenu="window.event.returnValue=false" >将彻底屏蔽鼠标右键特效 <table border oncontextmenu=return(false)><td>no</table> 可用于Table 2. <body onselectstart="return false"> 取消选取、防止复制 javascript技巧 3. onpaste="return false" 不准粘贴技巧 4. oncopy="return false;" oncut="return false;" 防止复制的javascirpt特效 |
相关文章推荐
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 用Javascript 禁止右键,复制,粘贴
- 用javascript 禁止右键,禁止复制,禁止粘贴
- javascript终极屏蔽右键/禁止复制/禁止另存/禁止右键/禁止选取/禁止粘贴的方法
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 用javascript 禁止右键,禁止复制,禁止粘贴
- 终极屏蔽右键 / 禁止复制 / 禁止另存 / 禁止选取 / 禁止粘贴的方法
- JavaScript 禁止复制与粘贴
- JavaScript 屏蔽鼠标右键、复制、粘贴、选择操作
- javascript中几个有意思的功能(目前5项) 1右键无效 2禁止网页复制 3禁止F5刷新 4新发现 5屏蔽js错误
- 【转】禁止另存网页、屏蔽选中、粘贴、复制、剪切、右键菜单(精)自己
- JS 禁止右键,禁止复制,禁止粘贴
- JavaScript禁止粘贴,禁止右键,禁止保存代码
- javascript禁止网页内容被复制和右键
- Javascript 代码片段 -- 禁止右键、选择、粘贴、shift、ctrl、alt.....
- javascript 防止复制+禁止右键
- JavaScript-禁止复制、粘贴