布尔教育吧 关注:259贴子:1,504
  • 2回复贴,共1

防止网站内容被复制粘贴的3中方法js实现

只看楼主收藏回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>
<title>js防止网页被复制</title>
</head>
<body oncontextmenu=self.event.returnValue=false onselectstart="return false">
<body>
请按下ctrl+c或者右键来复制看看
<textarea></textarea>
</body>
<script>
/**
*方法一开始
*/
function click() {
alert('谢绝复制!')
}
function clickl(){
if (event.button==2){
alert('请谅解!')
}
}
function ctrlkeydown(){
if (event.ctrlkey) {
alert('本网站禁止复制!')
}
}
document.onkeydown=ctrlkeydown;
document.onselectstart=click;
document.onmousedown=clickl;
/**
*方法二开始
*/
document.onmousedown = function() {
return false;
};
document.onselectstart = function() {
return false;
};
//屏蔽右键
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
/**
*方法三开始
*/
document.onkeydown = function(e){
var e=e||event;
if (e.ctrlKey==1 && e.keyCode==67){
return false;
}
}
document.body.oncopy = function (){
return false;
} //阻止复制
</script>
</html>


IP属地:陕西1楼2015-11-19 13:15回复
    在源代码里复制呢?


    来自Android客户端2楼2015-12-31 22:32
    回复
      其实比较简单的是,直接给页面加密,用源码也不能复制。以前见过一次那样的网站,恶心死了。


      IP属地:北京3楼2016-01-11 16:29
      回复