Onze vrijwilligers hebben dit artikel nog niet naar het Nederlands vertaald. Doe mee en help de klus te klaren!
U kunt het artikel ook in het English (US) lezen.

The oncontextmenu property of the GlobalEventHandlers mixin is an EventHandler that processes contextmenu events.

The contextmenu event typically fires when the right mouse button is clicked on the window. Unless the default behavior is prevented, the browser context menu will activate.


target.oncontextmenu = functionRef;


functionRef is a function name or a function expression. The function receives an Event object as its sole argument.

Only one oncontextmenu handler can be assigned to an object at a time. You may prefer to use the EventTarget.addEventListener() method instead, since it's more flexible.


Disabling context menus

This snippet prevents context menus from opening in the window. The context menu typically appears upon a right click.


<p>Try opening the context menu. Is it disabled?<p>


window.oncontextmenu = (e) => {


Pausing an animation

This example pauses a spinning shape whenever you open the context menu.


<div class="shape">Spinning</div>
<p class="note" hidden>Click to unpause.</p>


@keyframes spin {
  from {
    transform: rotate(0);
  to {
    transform: rotate(1turn);

.shape {
  width: 8em;
  height: 8em;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: spin 18s linear infinite;
  background: lightsalmon;
  border-radius: 42%;
  margin: 1em;

.paused {
  background-color: #ddd;

.paused .shape {
  animation-play-state: paused;


function pause(e) {

function play(e) {
  note.setAttribute('hidden', '');

const body = document.querySelector('body');
const note = document.querySelector('.note');

window.oncontextmenu = pause;
window.onpointerdown = play;



Specification Status Comment
HTML Living Standard
The definition of 'oncontextmenu' in that specification.
Living Standard  

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
oncontextmenuChrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera ? Safari ? WebView Android No support NoChrome Android No support NoFirefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?


Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

Unless the default behavior is prevented, the browser context menu will activate upon right-click. However, IE8 has a bug with this and will not activate the context menu if a contextmenu event handler is defined.

See also

Documentlabels en -medewerkers

Laatst bijgewerkt door: irenesmith,