menus.onClicked

メニューアイテムがクリックされたときに発火します。

他のブラウザーとの互換性のために Firefox はこのイベントを名前空間contextMenusmenuを経由して利用可能にしています。

書式

js
browser.menus.onClicked.addListener(listener);
browser.menus.onClicked.removeListener(listener);
browser.menus.onClicked.hasListener(listener);

イベントは 3 つの関数を持ちます:

addListener(callback)

このイベントのリスナーを追加します。

removeListener(listener)

リスニングを停止します。引数listenerは削除するリスナーです。

hasListener(listener)

listenerが登録されているかどうかを調べます。trueが返ればリスニング中、そうでなければfalseが返ります。

addListener の書式

パラメーター

callback

イベントが起こったときに呼ばれる関数です。以下の引数を渡されます:

info

menus.OnClickData. Information about the item clicked and the context where the click happened.

tab

tabs.Tab. The details of the tab where the click took place. If the click did not take place in or on a tab, this parameter will be missing.

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
onClicked

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Uses a non-standard name.
Has more compatibility info.

この例はメニューアイテムのクリックをリッスンし、アイテムの ID とタブの ID をログします:

js
browser.menus.create({
  id: "click-me",
  title: "Click me!",
  contexts: ["all"],
});

browser.menus.onClicked.addListener((info, tab) => {
  console.log("Item " + info.menuItemId + " clicked " + "in tab " + tab.id);
});

Example extensions

メモ: This API is based on Chromium's chrome.contextMenus API. This documentation is derived from context_menus.json in the Chromium code.