<!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>
<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>