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

How to use node to implement static file caching

Table of contents cache Cache location classifica...

Detailed tutorial on docker-compose deployment and configuration of Jenkins

Docker-compose deployment configuration jenkins 1...

Implementation code for using CSS text-emphasis to emphasize text

1. Introduction In the past, if you wanted to emp...

Detailed process of modifying hostname after Docker creates a container

There is a medicine for regret in the world, as l...

About dynamically adding routes based on user permissions in Vue

Display different menu pages according to the use...

jQuery achieves breathing carousel effect

This article shares the specific code of jQuery t...

Notes on MySQL case sensitivity

Table of contents MySQL case sensitivity is contr...

Detailed explanation of formatting numbers in MySQL

Recently, due to work needs, I need to format num...

Introduction to Computed Properties in Vue

Table of contents 1. What is a calculated propert...

HTML table markup tutorial (1): Creating a table

<br />This is a series of tutorials provided...

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQ...

Detailed explanation of the basic use of Apache POI

Table of contents Basic Introduction Getting Star...

Explanation of the basic syntax of Mysql database stored procedures

drop procedure sp_name// Before this, I have told...