Detailed explanation of how to prevent content from being selected, copied, or right-clicked in HTML pages

Detailed explanation of how to prevent content from being selected, copied, or right-clicked in HTML pages

Sometimes, we don't want the content presented in our web page to be stolen by someone with ulterior motives, so we need to add a function to prohibit copying on the web page. However, general browsers can still use copy as plain text after prohibiting copying, which cannot completely eliminate this problem. At this time, we need to completely prohibit right-clicking and copying on the page.

It is actually very simple to implement. You only need to add the following tags to the web page (note that it is immediately after the body):

<body topmargin="0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

This is just a preliminary method and can be easily cracked. If you are afraid that the webpage will be saved as a local file by others, you can add the following code to prevent others from saving it:

<noscript>  
<iframe src="*.htm"></iframe>  
</noscript>  

Finally, some webmasters may only need a function to prohibit copying, and do not need to prohibit right-clicking. In this case, add the following code in <body>:

<body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Use of MySQL stress testing tool Mysqlslap

>>:  Docker configuration Alibaba Cloud image acceleration pull implementation

Recommend

JS ES new feature of variable decoupling assignment

Table of contents 1. Decoupled assignment of arra...

Specific use of MySQL window functions

Table of contents 1. What is a window function? 1...

Several ways to use v-bind binding with Class and Style in Vue

Adding/removing classes to elements is a very com...

How to use jconsole to monitor remote Tomcat services

What is JConsole JConsole was introduced in Java ...

Summary of Linux nc command

NC's full name is Netcat (Network Knife), and...

JavaScript CollectGarbage Function Example

First, let's look at an example of memory rel...

Front-end JavaScript thoroughly understands function currying

Table of contents 1. What is currying 2. Uses of ...

How to add website icon?

The first step is to prepare an icon making softwa...

Logrotate implements Catalina.out log rotation every two hours

1. Introduction to Logrotate tool Logrotate is a ...

Detailed explanation of MySQL data rows and row overflow mechanism

1. What are the formats of lines? You can see you...

How to migrate local mysql to server database

We can use the scp command of Linux (scp cannot b...

Insufficient memory problem and solution when docker starts elasticsearch

question Insufficient memory when docker installs...

About the garbled problem caused by HTML encoding

Today a junior student asked a question. The HTML...

MySQL 8.0.18 Installation Configuration Optimization Tutorial

Mysql installation, configuration, and optimizati...

Detailed explanation of Vue life cycle

Table of contents Why understand the life cycle W...