Website Scripts And Cloud Tutorials

How to disable right click in webpage using javascript (single line)

Byadmin

Nov 12, 2013 ,

Last updated on March 1st, 2022 at 02:53 pm

Click to rate this tutorial!
[Total: 2 Average: 3]

Disable right click using javascript. Tired of searching and integrating so many complex scripts on your webpage just to disable the right click option?

Then here is a simple method inside the HTML or whatever page you want this to happen just add this oncontextmenu=”return false;” attribute along with the HTML tag not BODY tag as shown below

If you would like to alert some message, add customization or call some functions when user right click, check this tutorial.

In your website code, inside the body tag just replace the regular <html> with the code below

<html oncontextmenu="return false">

Add this code if you would like to have some custom alert messages included

<html oncontextmenu="alert('No Right Click Please');return false">

Tested in Mozilla FireFox, Google Chrome and Safari

It used to work with the oncontextmenu option inside body tag but not anymore. So use the above code within html tag.

<body oncontextmenu="return false;"> (NOT WORKING)

Demo (Try right click on the demo page and it will be disabled)

Click to rate this tutorial!
[Total: 2 Average: 3]

Leave a Reply

Your email address will not be published.