Nos bénévoles n'ont pas encore traduit cet article en Français. Inscrivez-vous et aidez-nous à réaliser cette tâche !
Vous pouvez également lire cet article en English (US).

GlobalEventHandlers.oncontextmenu is an event handler property for right-click events on the window. Unless the default behavior is prevented, the browser context menu will activate. Note that this event will occur with any non-disabled right-click event and does not depend on an element possessing the "contextmenu" attribute.

Syntax

window.oncontextmenu = funcRef;

Parameters

funcRef refers to the function to be called.

Example

These examples will disable right clicks on the page:

window.oncontextmenu = function () {
  return false;
};

window.addEventListener('contextmenu', function (e) {
  e.preventDefault();
}, false);

Specifications

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

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera ? Safari ? WebView Android No support NoChrome Android No support NoEdge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

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.

Étiquettes et contributeurs liés au document

Étiquettes : 
Dernière mise à jour par : mfluehr,