How to disable mouse right click on a web page? [duplicate] How to disable mouse right click on a web page? [duplicate] javascript javascript

How to disable mouse right click on a web page? [duplicate]


It's unprofessional, anyway this will work with javascript enabled:

document.oncontextmenu = document.body.oncontextmenu = function() {return false;}

You may also want to show a message to the user before returning false.

However I have to say that this should not be done generally because it limits users options without resolving the issue (in fact the context menu can be very easily enabled again.).

The following article better explains why this should not be done and what other actions can be taken to solve common related issues:http://articles.sitepoint.com/article/dont-disable-right-click


Firstly, if you are doing this just to prevent people viewing the source of your page - it won't work, because they can always use a keyboard shortcut to view it.

Secondly, you will have to use JavaScript to accomplish this. If the user has JS disabled, you cannot prevent the right click.

That said, add this to your body tag to disable right clicks.

<body oncontextmenu="return false;">


<body oncontextmenu="return false;"> works for me in Google Chrome. Not sure about other browsers.

Note, all someone has to do is disable JavaScript in order to see the right-click menu anyway.