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

Summary of methods to disable right-click menu and mouse drag selection on web pages_javascript techniques

WBOY
Release: 2016-05-16 16:13:22
Original
1350 people have browsed it

1. Disable mouse right-click menu:

There are two ways to disable the right mouse button

1. Add Javascript event handler to the Body tag of the HTML element. The code is as follows:

Copy code The code is as follows:


Note: You can also disable right-clicking on a specified location on the webpage. For example, you only want to disable right-clicking on a certain image in the webpage to prevent downloading, or you only want to disable right-clicking on a piece of text or a table in the webpage. You can You only need to add the above red code to the corresponding HTML tag element, for example:

Copy code The code is as follows:





Text content

2. Write a Javascript function and then call event processing. The code is as follows:

Copy code The code is as follows:


Note: Please pay attention to the code case! Copy the above code to between and of the HTML source code of the web page.

If you want to right-click to block the tag specified by the web page element, just change the document to the corresponding web page object tag name.

2. Disable dragging to select web page elements:

Just like the above example, there are the following two methods to disable the right mouse button

1. Add Javascript event handler to the Body tag of the HTML element. The code is as follows:

Copy code The code is as follows:


Description: Similar to the usage of right-click ban above

2. Write a Javascript function and then call event processing. The code is as follows:

Copy code The code is as follows:


Note: Please pay attention to the capitalization of sentences! Copy the above code to between and of the HTML source code of the web page.

If you want to right-click to block the tag specified by the web page element, just change the document to the corresponding web page object tag name.

To sum up, if we want to disable both the right-click menu and mouse dragging of the web page, we can use the following two methods:

Method 1:

Copy code The code is as follows:


Method 2:

Copy code The code is as follows:


The above is a summary of my commonly used methods and is not comprehensive. If you have other methods, please leave me a message. This article will continue to be updated.

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