屏蔽右键代码(防止网页恶意复制)

为保护自己网站内容不被盗取滥用,保护自己网站的知识产权,本人昨天找了不少关于如何屏蔽右键复制的代码。大概有如下几种:

pjhome中找到的方法:

引用内容 引用内容
在head.asp中的
<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()’,因为这段代码的意思是当鼠标键弹起时,选择的内容为空,这样就会影响正常的登陆哦。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注