封鎖網頁內容
用 Javascript 來封鎖網頁內容的複製
包含三項封鎖
1. setInterval(“window.clipboardData.setData(‘text’,”)”,2) : 清除掉剪貼簿
2. oncontextmenu : 封鎖滑鼠右鍵時會觸發事件
3. onselectstart : 封鎖選取拖放事件
sample code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <head> </head> <body onload=setInterval("window.clipboardData.setData('text','')",2) oncontextmenu="return false" onselectstart="return false"> ************************************************ ***********To disable right click in the web page************** <script language=JavaScript> function clickIE() { if (document.all) { return false; } } function clickNS(e) { if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) { return false; } } } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS; } else { document.onmouseup=clickNS; document.oncontextmenu=clickIE; } document.oncontextmenu=new Function("return false") </script> ************************************************ ****************To Disable Text Selection*************** <script language="JavaScript1.2"> function disableselect(e){ return false } function reEnable(){ return true } //if IE4+ document.onselectstart=new Function ("return false") //if NS6 if (window.sidebar){ document.onmousedown=disableselect document.onclick=reEnable } </script> </body> |