Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

contextMenus.update()

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

Updates a previously created context menu item.

Syntax

chrome.contextMenus.update(
  id,               // integer or string
  updateProperties, // object
  function() {...}  // optional function
)

This API is also available as browser.contextMenus.update() in a version that returns a promise.

Parameters

id
integer or string. The ID of the item to update.
updateProperties
object. The properties to update. Accepts the same values as create().
typeOptional
contextMenus.ItemType. The type of menu item: "normal", "checkbox", "radio", "separator". Defaults to "normal".
titleOptional
string. The text to be displayed in the item; this is mandatory unless type is "separator".
checkedOptional
boolean. The initial state of a checkbox or radio item: true for selected and false for unselected. Only one radio item can be selected at a time in a given group of radio items.
contextsOptional
array of contextMenus.ContextType. Array of contexts in which this menu item will appear. Defaults to ['page'] if not specified.
onclickOptional
function. A function that will be called when the menu item is clicked. Event pages cannot use this: instead, they should register a listener for contextMenus.onClicked.
parentIdOptional
integer or string.  The ID of a parent menu item; this makes the item a child of a previously added item. Note: You cannot change an item to be a child of one of its own descendants.
documentUrlPatternsOptional
array of string. Lets you restrict the item to apply only to documents whose URL matches one of the given match patterns. This applies to frames as well.
targetUrlPatternsOptional
array of string. Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags.
enabledOptional
boolean. Whether this context menu item is enabled or disabled. Defaults to true.
callbackOptional
function. Called when the context menu has been updated.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes Yes 48.0 No 33

Compatibility notes

Firefox

  • documentUrlPatterns is supported from Firefox 50.

Examples

This example creates a context menu item, then updates its title when the user clicks it:

function onUpdated() {
  if (chrome.runtime.lastError) {
    console.log("error updating item:" + chrome.runtime.lastError);
  } else {
    console.log("item updated successfully");
  }
}

chrome.contextMenus.create({
  id: "do-not-click-me",
  title: "Do not click this button",
  contexts: ["all"]
});

chrome.contextMenus.onClicked.addListener(function(info, tab) {
  if (info.menuItemId == "do-not-click-me") {
    chrome.contextMenus.update(info.menuItemId, {
      title: "Do not click this button again"
    }, onUpdated);
  }
});

Example add-ons

Acknowledgements

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

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

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

 このページの貢献者: Makyen, wbamberg
 最終更新者: Makyen,