Home > Web Front-end > JS Tutorial > body text

Various ways to prohibit copying of website content

韦小宝
Release: 2017-11-29 10:10:29
Original
2296 people have browsed it

I believe many students have encountered websites when they browse the website. The content cannot be copied. This is very annoying. Today we will take you to see how to implement this kind of web page bancontentThe effect of copying, let us take a look at the many ways to prohibit the copying of content!

First method:
Add the following js code

<script type="text/javascript">
// oncontextmenu 事件在元素中用户右击鼠标时触发并打开上下文菜单
document.oncontextmenu=new Function("event.returnValue=false"); 
// onselectstart几乎可以用于所有对象,其触发时间为目标对象被开始选中时(即选中动作刚开始,尚未实质性被选中)
document.onselectstart=new Function("event.returnValue=false"); 
</script>
Copy after login

Example:








火影忍者

十多年前一只拥有巨大威力的妖兽“九尾妖狐”袭击了木叶忍者村,当时的第四代火影拼尽全力,以自己的生命为代价将“九尾妖狐”封印在了刚出生的鸣人身上。木叶村终于恢复了平静,但村民们却把鸣人当成像“九尾妖狐”那样的怪物看待,所有人都疏远他。 鸣人自小就孤苦无依,一晃十多年过去了,少年鸣人考入了木叶村的忍者学校,结识了好朋友佐助和小樱。佐助是宇智波家族的传人之一,当他还是小孩的时候他的哥哥——一个已经拥有高超忍术的忍者将他们家族的人都杀死了,然后投靠了一直想将木叶村毁灭的大蛇丸,佐助自小就发誓要超越哥哥,为家族报仇。鸣人他们在忍者学校得到了教官卡卡西的精心指点,在他的帮助下去迎接成长中的一次又一次挑战!

<script type="text/javascript"> // oncontextmenu 事件在元素中用户右击鼠标时触发并打开上下文菜单 document.oncontextmenu=new Function("event.returnValue=false"); // onselectstart几乎可以用于所有对象,其触发时间为目标对象被开始选中时(即选中动作刚开始,尚未实质性被选中) document.onselectstart=new Function("event.returnValue=false"); </script>
Copy after login

Second method:
Add the following code to :

 <body oncontextmenu="return false" onselectstart="return false"> 
或 
<body oncontextmenu="event.returnValue=false" onselectstart="event.returnValue=false">
Copy after login


This method of adding code to body One flaw is that it depends on the content of the body. If the body has less content, you can still copy the content of the website by selecting the content from the bottom of the body upwards.

The third method:
If you only limit copying, you can add the following code to :

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>
*{margin: 0;padding: 0;}
.container h1 {color: gold;text-align:center;margin-bottom:30px;}
.container p {width: 500px;margin:0 auto;color: purple;text-indent: 30px;}
</style>
</head>
<body oncopy="alert(&#39;对不起,禁止复制!&#39;);return false;">
<div>
<h1>火影忍者</h1>
<p>
十多年前一只拥有巨大威力的妖兽“九尾妖狐”袭击了木叶忍者村,当时的第四代火影拼尽全力,以自己的生命为代价将“九尾妖狐”封印在了刚出生的鸣人身上。木叶村终于恢复了平静,但村民们却把鸣人当成像“九尾妖狐”那样的怪物看待,所有人都疏远他。 鸣人自小就孤苦无依,一晃十多年过去了,少年鸣人考入了木叶村的忍者学校,结识了好朋友佐助和小樱。佐助是宇智波家族的传人之一,当他还是小孩的时候他的哥哥——一个已经拥有高超忍术的忍者将他们家族的人都杀死了,然后投靠了一直想将木叶村毁灭的大蛇丸,佐助自小就发誓要超越哥哥,为家族报仇。鸣人他们在忍者学校得到了教官卡卡西的精心指点,在他的帮助下去迎接成长中的一次又一次挑战! 
</p>
</div>
</body>
</html>
Copy after login

Fourth method:
Disable Ctrl+C and Ctrl+V, code:

// 禁用Ctrl+C和Ctrl+V(所有浏览器均支持)
$(document).keydown(function(e) {
  if(e.ctrlKey && (e.keyCode == 86 || e.keyCode == 67)) {
    return false;
  }
});
Copy after login

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style>
*{margin: 0;padding: 0;}
.container h1 {color: gold;text-align:center;margin-bottom:30px;}
.container p {width: 500px;margin:0 auto;color: purple;text-indent: 30px;}
</style>
</head>
<body>
<div>
<h1>火影忍者</h1>
<p>
十多年前一只拥有巨大威力的妖兽“九尾妖狐”袭击了木叶忍者村,当时的第四代火影拼尽全力,以自己的生命为代价将“九尾妖狐”封印在了刚出生的鸣人身上。木叶村终于恢复了平静,但村民们却把鸣人当成像“九尾妖狐”那样的怪物看待,所有人都疏远他。 鸣人自小就孤苦无依,一晃十多年过去了,少年鸣人考入了木叶村的忍者学校,结识了好朋友佐助和小樱。佐助是宇智波家族的传人之一,当他还是小孩的时候他的哥哥——一个已经拥有高超忍术的忍者将他们家族的人都杀死了,然后投靠了一直想将木叶村毁灭的大蛇丸,佐助自小就发誓要超越哥哥,为家族报仇。鸣人他们在忍者学校得到了教官卡卡西的精心指点,在他的帮助下去迎接成长中的一次又一次挑战! 
</p>
</div>

<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).keydown(function(e) {
 if(e.ctrlKey && (e.keyCode == 86 || e.keyCode == 67)) {
  alert(&#39;不能Ctrl+C和Ctrl+V复制、粘贴&#39;);
   return false;
 }
});
</script>
</body>
</html>
Copy after login

The above is all the content of various methods to prohibit copying of website content. If you are interested, please go to PHP Chinese NetSearch for more~

Related recommendations:

Detailed explanation of WeChat prohibition of copying links in React Js Share a case study of prohibiting the hiding of the upper right corner menu function

#The html page prohibits right-clicking, prohibiting copying, prohibiting image dragging, prohibiting copying and cutting

javascript No copying of web pages_javascript skills

The above is the detailed content of Various ways to prohibit copying of website content. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template