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

CSS+HTML to realize the top navigation bar function

Implementation of navigation bar, fixed top navig...

Example of using CSS3 to create Pikachu animated wallpaper

text OK, next it’s time to show the renderings. O...

Four ways to modify the default CSS style of element-ui components in Vue

Table of contents Preface 1. Use global unified o...

Vue implements tree table through element tree control

Table of contents Implementation effect diagram I...

Docker configures the storage location of local images and containers

Use the find command to find files larger than a ...

How to make a website front end elegant and attractive to users

The temperament of a web front-end website is a fe...

IE8 provides a good experience: Activities

Today I had a sneak peek at IE8 beta 1 (hereafter...

15-minute parallel artifact GNU Parallel Getting Started Guide

GNU Parallel is a shell tool for executing comput...

Summary of several submission methods of HTML forms

The most common, most commonly used and most gener...

Element UI table realizes drop-down filtering function

This article example shares the specific code for...

Causes and solutions for MySQL deadlock

The database, like the operating system, is a sha...

Detailed explanation of Angular data binding and its implementation

Table of contents Preface What is data binding? T...

JavaScript to implement login slider verification

This article example shares the specific code of ...

Setting up a proxy server using nginx

Nginx can use its reverse proxy function to imple...