将子项添加到上下文菜单链接 [英] Adding children to context menu links
问题描述
我正在尝试为我的上下文菜单添加子项,但由于某种原因,它不适合我。这里是我的代码:
var parent1 = chrome.contextMenus.create({title:Trigger Rank,contexts :[链接]});
var child1 = chrome.contextMenus.create
(
{title:Rank 1,parentId:parent1,onclick:genericOnClick}
);
var child2 = chrome.contextMenus.create
(
{title:Rank 2,parentId:parent1,onclick:genericOnClick}
);
var child2 = chrome.contextMenus.create
(
{title:Rank 3,parentId:parent1,onclick:genericOnClick}
);
var parent2 = chrome.contextMenus.create({title:Target Rank,contexts:[link]});
var child1 = chrome.contextMenus.create
(
{title:Rank 1,parentId:parent2,onclick:genericOnClick}
);
var child2 = chrome.contextMenus.create
(
{title:Rank 2,parentId:parent2,onclick:genericOnClick}
);
var child3 = chrome.contextMenus.create
(
{title:Rank 3,parentId:parent2,onclick:genericOnClick}
);
看起来非常简单,但这是我第一次使用chrome扩展,并且第一次使用javascript编写。所以可能是我错过了一些东西。
目前,当右键点击一个链接时,只显示父母(而不是孩子)。 b
如果我的问题太过新手,请提前致谢。 :)
$ c> [link] ,但是您的子项具有 [page]的默认上下文
/ code>。因此:
- 当您右键单击链接时,父母出现,但孩子没有,因为他们没有设置在链接上显示。
- 当您右键单击除链接之外的其他内容时,父母不会显示,因此孩子也不会显示。
$您必须设置您的孩子的上下文
值以匹配父母的 [b
$ b < link]
值。
I am trying to add children for my context menu, but for some reason it is not working for me. Here is my code:
var parent1 = chrome.contextMenus.create({"title": "Trigger Rank", "contexts":["link"]});
var child1 = chrome.contextMenus.create
(
{"title": "Rank 1", "parentId": parent1, "onclick": genericOnClick}
);
var child2 = chrome.contextMenus.create
(
{"title": "Rank 2", "parentId": parent1, "onclick": genericOnClick}
);
var child2 = chrome.contextMenus.create
(
{"title": "Rank 3", "parentId": parent1, "onclick": genericOnClick}
);
var parent2 = chrome.contextMenus.create({"title": "Target Rank", "contexts":["link"]});
var child1 = chrome.contextMenus.create
(
{"title": "Rank 1", "parentId": parent2, "onclick": genericOnClick}
);
var child2 = chrome.contextMenus.create
(
{"title": "Rank 2", "parentId": parent2, "onclick": genericOnClick}
);
var child3 = chrome.contextMenus.create
(
{"title": "Rank 3", "parentId": parent2, "onclick": genericOnClick}
);
Seems pretty straight forward but it's my first chrome extension, and first time writing in javascript. So might be that I am missing something.
Currently when right clicking a link, ONLY the parents are shown (and not the children).
Thanks in advance and sorry if my question is too "newbie". :)
解决方案 Your parent items have contexts
set to ["link"]
, but your children items have the default contexts
of ["page"]
. Therefore:
- when you right-click on a link, the parents show up, but the children do not, because they're not set to show up on links.
- when you right-click on something besides a link, the parents don't show up, so the children aren't shown either.
You must set your children's contexts
values to match the parents' ["link"]
value.
这篇关于将子项添加到上下文菜单链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!