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

contextMenus.remove()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!

Removes a context menu item.

Syntax

chrome.contextMenus.remove(
  menuItemId,      // integer or string
  function() {...} // optional function
)

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

Parameters

menuItemId
integer or string. The ID of the context menu item to remove.
callbackOptional
function. Called when the context menu has been removed. If the item could not be found or some other error occurs, runtime.lastError will be set, and you can check for it in this function.

Browser compatibility

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

Examples

This add-on adds a context menu item labeled "Remove me!". If you click the item, the add-on removes it.

function onCreated() {
  if (chrome.runtime.lastError) {
    console.log("error creating item:" + chrome.runtime.lastError);
  } else {
    console.log("item created successfully");
  }
}

function onRemoved() {
  if (chrome.runtime.lastError) {
    console.log("error removing item:" + chrome.runtime.lastError);
  } else {
    console.log("item removed successfully");
  }
}

chrome.contextMenus.create({
  id: "remove-me",
  title: "Remove me!",
  contexts: ["all"]
}, onCreated);

chrome.contextMenus.onClicked.addListener(function(info, tab) {
  if (info.menuItemId == "remove-me") {
    chrome.contextMenus.remove(info.menuItemId, onRemoved);
  }
});

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,