防止他人復制粘貼網頁內容代碼

一、對整個網頁生效的代碼。
1、第1種辦法:在網頁<head>與<body>之間的位置加入如下js語言代碼:
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false");
document.onselectstart=new Function("event.returnValue=false");
</script>
2、第二種辦法:在<body>中添加代碼。
<body onselectstart="return false" oncontextmenu="return false">或
<body oncontextmenu="event.returnValue=false" onselectstart="event.returnValue=false">
二、上面代碼的意思:同時使“右鍵菜單”和”選擇復制”失效。
讓右鍵菜單失效或讓復制失效均可達到防止他人復制的目的,所以上面的代碼可以只保留其中一項就可以了。所以上面的代碼第一種方法可以簡化為:
<script language="Javascript">
document.oncontextmenu=new Function("event.returnValue=false");
</script> 或
<script language="Javascript">
document.onselectstart=new Function("event.returnValue=false");
</script>
第2種方法代碼可以簡化為:
<body onselectstart="return false">或
<body oncontextmenu="return false">或
<body oncontextmenu="event.returnValue=false">或
<body onselectstart="event.returnValue=false">
三、對網頁中特定部分防止復制粘貼。
只能使用上面講到的第二種方法,將類似【onselectstart="return false"】的代碼,放入<table>或<td>或<p>或<div>等標簽中以防止他人對網頁特定內容的復制粘貼。例如:
<table onselectstart="return false">
四、如果只限制復制,可以在<body>加入以下代碼:
<body oncopy="alert('對不起,禁止復制!');return false;">
此方法也可以只限制復制網頁中的特定部分,例如:
<table oncopy="alert('對不起,禁止復制!');return false;">
五、使菜單"文件"-"另存為"失效。
如果只是禁止了右鍵和選擇復制,別人還可以通過瀏覽器菜單中的"文件"-"另存為"拷貝文件。為了使拷貝失效,可以在<body>與</body>之間加入以下代碼:
<noscript>
<iframe src="*.htm"></iframe>
</noscript>

 
  • 本文由 米粒在線 發表于 2012年11月11日13:17:02
  • 轉載請務必保留本文鏈接:http://www.bjmhhq.com/881.html

發表評論

匿名網友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
確定

拖動滑塊以完成驗證