Disable right click and F12 key using JavaScript

In this short article, we’ll explain to you how to disable right click using JavaScript. Sometimes you want to disable right-click to protect your own content or information from the user.

You need to just add the following script code in the <body> section.

With the help of the above code, we can disable the right click using preventDefault() method in contextmenu event. Also disable the F12 , Ctrl + Shift + I, Ctrl + Shift + J and Ctrl + U keys.

Instead of the contextmenu event, You can also add the oncontextmenu handler into the HTML body tag to disable the right click. Check out the following code.

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

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