Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent context menu from opening on a right click over element

Tags:

People also ask

How do I disable default 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.

What do you call the menu that pops up when you right click?

A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.

How do you right click a context menu?

Right-click on the “shell” key, and then choose New > Key from the menu. Give the new key the name that you want to show up on the desktop context menu. For this example we'll be using Notepad.


I want my website to have a custom interaction when the user right clicks on an element, <div class="myElement"></div>. Thus, I don't what the context menu to also pop up when the element is right clicked as to not spoil the UX. Is there a way to do this (preferably in CSS, but vanilla js works too)?

Desired:

.myElement {
    contextMenuOnRightClick: none,
}