Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I want to disable mouse right click on an HTML page. I have a page where user has to enter the details. I don't want the user to see the menu thats get displayed with the mouse right click. Rather I want to display a custom menu. I know there are some plugins available to do that. But my requirement does not need any plugins.

like image 506
Puru Avatar asked Jun 21 '10 10:06

Puru


People also ask

Is it possible to disable right click?

Hello Jim Lane, You will be able to disable right click option in Windows, but you will not be able to disable on any particular program like Internet Explorer and other Browsers. Follow these steps to disable mouse right click option on Windows.

How do I override right click?

To override the default browser right-click menu, the first step is to prevent the default right-click behavior. This can be done by listening to the contextmenu event and using the preventDefault() method on the event.

How do I disable right click on Chrome?

Method 2: Disable JavaScript in Web Browser Be that as it may, here's how you can turn off JavaScript in Chrome, Firefox, and Edge. On Chrome, go to 'Settings -> Privacy and Security -> Site Settings -> JavaScript' and then switch off the toggle.


1 Answers

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

like image 137
Andrea Zilio Avatar answered Sep 21 '22 18:09

Andrea Zilio