Chrome扩展程序:如何使用自定义名称创建上下文菜单,而不是插件名称

时间:2015-09-17 14:52:25

标签: google-chrome google-chrome-extension contextmenu

我正在尝试创建基本的Chrome扩展程序。在发现root context menu can only contain one item per plugin之后,我想至少能够为父母命名而不是我的插件名称:

chrome.contextMenus.create({
    title: "Child Item 1",
    contexts:["selection"],
});
chrome.contextMenus.create({
    title: "Child Item 2",
    contexts:["selection"],
});

http://i.imgur.com/hsObtyL.png

那我该怎么做?

1 个答案:

答案 0 :(得分:9)

我这样做的方法是创建一个包含自定义titleid的父项,然后将我需要的所有项目作为子项添加到父项目(添加到script.js 1}}文件):

chrome.contextMenus.create({
    title: "Custom Parent Name",
    contexts:["selection"],
    id: "parent",
});
chrome.contextMenus.create({
    title: "Child Item 1",
    contexts:["selection"],
    parentId: "parent",
    id: "child1",
});
chrome.contextMenus.create({
    title: "Child Item 2",
    contexts:["selection"],
    parentId: "parent",
    id: "child2",
});

结果如下:

Result