關於如何屏蔽右鍵復制的代碼。大概有如下幾種:
<head>語句下輸入
- <body onselectstart="return false;" oncontextmenu="return false;" >
在系統首頁文件(default.asp)和日志文件(article.asp)最底下加入如下代碼即可.這兩個文件都在根目錄下.
- <noscript>
- <iframe scr="*.htm"></iframe>
- </noscript>
- <script language="JavaScript">
- document.oncontextmenu=new Function("event.returnValue=false;");
- document.onselectstart=new Function("event.returnValue=false;");
- </script>
優點是簡單易行,但保護不夠,很容易破解。
找到的一些辦法:
第一種 禁止右鍵、Ctrl鍵和復制功能的JS代碼
有的t網站頁面禁止使用右鍵和復制功能,甚至連Ctrl鍵也禁止掉了,這個效果是如何實現的呢?其實很簡單就是調用了一段JS代碼而已。
下面文本框中就是實現效果所需代碼:
- 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文件,然后在想實現此效果的頁面用<!--#include file="*.js" -->調用即可,*代表你另存的文件名!
第二種 禁用右鍵並自動導航
腳本說明:
把如下代碼加入<body>區域中
- <script language="javascript">
- if (navigator.appName.indexOf("Internet Explorer") != -1)
- document.onmousedown = noSourceExplorer;
- function noSourceExplorer()
- {
- if (event.button == 2 | event.button == 3)
- {
- alert("禁止右鍵...去首頁!");
- location.replace("http://xiaoc.icpcn.com");
- }
- }
- </script>
第三種 禁用右鍵代碼
將以下代碼加到〈head〉與〈/head〉之間
- <script language="JavaScript">
- document.oncontextmenu=new Function("event.returnValue=false;");
- document.onselectstart=new Function("event.returnValue=false;");
- </script>
優點是使用了JS腳本,但是比較復雜,也很容易破解。
推薦使用的方法:
在網頁腳本中(header.asp)插入以下代碼:
- <body oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
上面代碼的意思是當鼠標選中文字時為空
優點是代碼容易實現,不需要JS腳本的支持。且在一般的破解復制后,也會清空剪貼板。
其中,我去除了onmouseup='document.selection.empty()',因為這段代碼的意思是當鼠標鍵彈起時,選擇的內容為空,這樣就會影響正常的登陸哦。