Skip to content
Fix Code Error

How do I disable right click on my web page?

March 13, 2021 by Code Error
Posted By: Anonymous

Can I disable right click on my web page without using JavaScript? I ask this because most browsers allow user to disable JavaScript.

If not, how do I use JavaScript to disable right click?

Solution

You can do that with JavaScript by adding an event listener for the “contextmenu” event and calling the preventDefault() method:

document.addEventListener('contextmenu', event => event.preventDefault());

That being said: DON’T DO IT.

Why? Because it achieves nothing other than annoying users. Also many browsers have a security option to disallow disabling of the right click (context) menu anyway.

Not sure why you’d want to. If it’s out of some misplaced belief that you can protect your source code or images that way, think again: you can’t.

Answered By: Anonymous

Related Articles

  • Form field border-radius is not working only on the last…
  • Trouble with boxes appearing/hiding based on selection
  • Problems Installing CRA & NextJS from NPM (Error:…
  • Generating a drop down list of timezones with PHP
  • Ubuntu apt-get unable to fetch packages
  • React Multi-level push menu SCSS Back button not working
  • How Spring Security Filter Chain works
  • An Authentication object was not found in the…
  • TLS 1.3 server socket with Java 11 and self-signed…
  • Rails wrong number of arguments error when generating…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Unicode (UTF-8) reading and writing to files in Python

Next Post:

Use jQuery to hide a DIV when the user clicks outside of it

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error