A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/Event/contextmenu below:

contextmenu · WebPlatform Docs

contextmenu Overview Table Synchronous No Bubbles No Target dom/Element Cancelable No Default action ?

## Examples

This example shows how to prevent a context menu from appearing by canceling the oncontextmenu event handler.

<span style="width: 300px; background-color: blue; color: white;"
    oncontextmenu="return false">
The context menu never displays when you right-click in this box. </span>

View live example

Although area elements inherit the oncontextmenu event by way of the object hierarchy, they do not respond to right-click events in Internet Explorer. However, it is possible to imitate the desired behavior by using the onfocus and onblur events to determine the currently selected region and trigger the appropriate action in the context menu handler of the img itself. Although it isn’t used by Internet Explorer, retain the oncontextmenu event attribute on the area elements for a fully cross-client implementation.

<script type="text/javascript">
var selectedArea = null;
function activate(e,f) {
    selectedArea = f ? e : null;
}
function menu(e) {
    if (selectedArea)
        alert('right-click: ' + selectedArea.id);
    else {
        
        if (e.tagName == 'AREA')
            alert('right-click: ' + e.id);
        else
            alert('right-click: ' + e.tagName);
    }
    return false;
}
</script>
<map id="Map0">
<area id="Area1" onfocus="activate(this,true)" onblur="activate(this,false)"
    oncontextmenu="return menu(this)" shape="rect" coords="100, 50, 200, 150" href="..."/>
</map>
<img src="..." oncontextmenu="return menu(this)" usemap="#Map0" />

View live example

Notes Remarks

Opens the context menu. To cancel the default behavior, set the returnValue property of the event object to false. To invoke this event, do one of the following:

The pEvtObj parameter is required for the following interfaces:

Syntax Standards information

There are no standards that apply here.

Event handler parameters
pEvtObj [in]
Type: ****IHTMLEventObj****
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4