menus.overrideContext() 编辑

Hide all default Firefox menu items in favor of providing a custom context menu UI.

The overrideContext method will cause the matching menu items from this extension to be shown instead of the default menu. This method should be called from a contextmenu DOM event handler, and only applies to the menu that opens after this event.

This interface requires the menus.overrideContext permission.

Syntax

browser.menus.overrideContext(
  contextOptions // object
)

Parameters

contextOptions
object. Options for how the context menus will be overridden.
showDefaults Optional
boolean. Whether to also include default menu items in the menu.
contextOptional
string. ContextType to override, to allow menu items from other extensions in the menu. Currently only 'bookmark' and 'tab' are supported. showDefaults cannot be used with this option.
bookmarkIdOptional
string. Required when context is 'bookmark'. Requires 'bookmark' permission.
tabIdOptional
integer. Required when context is 'tab'. Requires 'tabs' permission.

Examples

Open the tab context menu on your custom UI, in this case :

document.addEventListener('contextmenu', event => {
  const foo = event.target.closest('.foo');
  if (foo) {
    // When the context menu is opened on an element with the foo class
    // set the context to "opening a tab context menu".
    browser.menus.overrideContext({
      context: 'tab',
      tabId: parseInt(foo.dataset.tabId)
    });
  }
}, { capture: true });

See this blog post for more details.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:66 次

字数:2618

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文