mozbrowsercontextmenu

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!
この記事を English (US) で読むこともできます。

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The mozbrowsercontextmenu event is fired when the user tried to access a context menu over a browser <iframe>. This event can be used to control what will appear in the menu.

General info

Specification
Non standard
Interface
CustomEvent
Bubbles
Yes
Cancelable
Yes
Target
<iframe>
Default Action
None

Properties

Property Type Description
target Read only EventTarget The browser iframe
type Read only DOMString The type of event.
bubbles Read only Boolean Whether the event normally bubbles or not
cancelable Read only Boolean Whether the event is cancellable or not?
details Read only Object A custom object

details

The details property returns an anonymous JavaScript object with the following properties:

clientX
The X value of the coordinate that was clicked inside the browser <iframe>'s viewport.
clientY
The Y value of the coordinate that was clicked inside the browser <iframe>'s viewport.
systemTargets
An array containing one or more MenuSystem objects (see The MenuSystem object, below), containing details of the standard menu(s) that will be shown. For example, if the user clicked on an image nested in an <a> tag, two menus are available — one with information related to the image, and one for the link.
contextmenu
A Menu object (see The Menu object, below) representing a custom menu defined via <menu> / <menuitem> elements and pointed to via a contextmenu attribute on the DOM element clicked on, which contains the menu's id.
contextmenuItemSelected
An anonymous function that fires when a menu item is selected.

The MenuSystem object

An object defining a standard context menu that will be displayed. Its properties are as follows:

documentURI
A DOMString representing the URL of the document the menu is associated with.
uri
A DOMString. In the case of an image or video context menu, this is the src of the image or video clicked on to get the context menu. In the case of an link context menu, it is the link's href.
text
A DOMString representing the text of the link clicked on, in the case of a link context menu.
hasVideo
A Boolean. In the case of a video context menu, this returns true if the video has metadata and is bigger than 0 x 0, or false if not.
action
A DOMString representing the action of a form, in the case of a form context menu.
method
A DOMString representing the method of a form, in the case of a form context menu.
name
A DOMString representing the name of a form, in the case of a form context menu.

The Menu object

An object representing a custom menu defined via <menu> / <menuitem> elements and pointed to via a contextmenu attribute on the DOM element clicked on, which contains the menu's id. Its properties are as follows:

type
A DOMString representing the type of context menu displayed. It can be menu (a full menu) or menuitem (a single menu item.)
label
A DOMString equal to the label attribute of the DOM node the context menu is accessed on.
icon
The menu item's icon, if the context menu being accessed is a menu item.
id
The menu item's id, if the context menu being accessed is a menu item. This is passed to the contextmenuItemSelected() function, to indicate which item has been selected.
items
An array of further Menu objects, which indicate the menu options available in a menu, if the context menu being accessed is a menu.

Example

var browser = document.querySelector("iframe");

browser.addEventListener("mozbrowsercontextmenu", function(event) {
  console.log("Asking for menu:" + JSON.stringify(event.details));
});

See also

ドキュメントのタグと貢献者

 このページの貢献者: chrisdavidmills, teoli, kscarfone, Jeremie
 最終更新者: chrisdavidmills,