问题描述
我目前可以在Google Chrome扩展程序中创建以下contextMenu(右键菜单):
I can currently create a contextMenu (right-click menu) in a Google Chrome extension as follows:
chrome.contextMenus.create({
title: "The name to click",
contexts:["selection"],
onclick: theFunctionToRun
});
但是,我希望能够添加子菜单的contextMenu.我正在实现10个可以通过右键单击菜单调用的工具,但是我希望有2个菜单,每个菜单都基于5个工具的分类.
However, I would like to be able to add a contextMenu of submenus. I am implementing 10 tools that can be invoked through the right-click menu, but would like to have 2 menus each with 5 tools in them based on their categorization.
我无法在线或在文档中找到任何有关此的信息.我很惊讶其他人也不想使用此功能,所以也许我只是在寻找错误的东西.
I have not been able to find any info online or in documentation about this. I'm surprised other people do not want this feature as well so maybe I am just searching for the wrong thing.
是否可以创建子菜单的contextMenu?如果是这样,我该怎么办?
Is creating a contextMenu of submenus possible? If so, how can I do this?
推荐答案
我知道了.我需要在父菜单中指定一个ID,然后在其他菜单中引用父ID,如下所示:
I figured it out. I needed to specify an id in the parent menu and then reference the parent ID in the other menus as follows:
chrome.contextMenus.create({
title: "The name of the parent menu",
id: "parent",
contexts:["selection"]
});
chrome.contextMenus.create({
title: "The first action to click",
parentId: "parent",
contexts:["selection"],
onclick: theFirstFunction
});
chrome.contextMenus.create({
title: "The second action to click",
parentId: "parent",
contexts:["selection"],
onclick: theSecondFunction
});
这篇关于在Google Chrome扩展程序中添加子contextMenus的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!