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

How to disable right click using JavaScript

藏色散人
Release: 2019-01-19 16:30:51
Original
3292 people have browsed it

Web newbies often believe that they can prevent web page content from being stolen by preventing visitors from using the right-click context menu. Nothing could be further from the truth.

How to disable right click using JavaScript

More experienced users can easily bypass the problem of disabling the right click, and accessing most web page code itself is a basic function of the web browser and is not required at all. Right click.

Disadvantages

There are many ways to get around "no right-click script" when in reality the only effect of such a script is to annoy those who are legitimately using it in web navigation Visitors to the right-click context menu (the correct name of the menu).

Also, all the scripts I've seen that do this only block access to the context menu from the right mouse button. They didn't take into account the fact that the menu is also accessible via keyboard.

Everyone who needs to access the menu uses the 104-key keyboard to select the object on the screen they want to access the context menu (e.g. by left clicking on it) and then press the CTRL key immediately left of the context menu on the keyboard keys on computer keyboard.

On a 101-key keyboard, you can hold down the shift key and press F10 to perform a right-click command.

JavaScript

If you want to disable right-click on a web page, here is a very simple JavaScript you can use to prevent access to the context menu All access (not just the right mouse button, but also the keyboard) - this can really annoy your visitors.

This script is even simpler than most scripts that just block the mouse buttons, and it works in almost all browsers.

Here is the complete script:

<body oncontextmenu="return false;">
Copy after login

Just a small snippet of code added to the body tag of a web page is more effective at preventing visitors from accessing the context menu than many no-right-click scripts that you This can be found elsewhere online as it blocks access to the mouse and keyboard options mentioned above.

Limitations

Of course, this script will not work in all web browsers (for example, Opera will ignore it - but Opera will also ignore all other Script that doesn't require right click).

This script also does not prevent visitors from accessing the page source using the View source option in their browser menu, or from saving a web page and viewing the source code of a saved copy in their favorite editor.

Finally, although you may disable access to the context menu, users can easily re-enable access by simply typing

javascript:void oncontextmenu(null)
Copy after login

into the browser's address bar.

The above is the detailed content of How to disable right click using JavaScript. 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