【发布时间】:2023-03-12 05:05:02
【问题描述】:
在 Google Chrome 扩展程序中,我知道如何在所选文本上显示上下文菜单。
chrome.contextMenus.create({
'title': 'TEST',
'contexts': ['selection'],
'id': "test"
});
chrome.contextMenus.create({
'title': 'submenu',
'contexts': ['selection'],
'id': "test_1",
'parentId': "test",
'onclick': menu.onClicked_
});
但我只想在所选文本位于“可编辑元素”中时才显示此菜单(输入文本、文本区域、内容可编辑 DIV,...)。我该怎么做?
谢谢!
【问题讨论】:
-
您是否尝试过使用上下文
"editable"而不是"selection"?文档对它的含义不是很清楚。 -
使用
"editable",菜单仅出现在可编辑元素中。但即使没有选择文本,它也会出现。 -
那么我怀疑这是可以实现的。
标签: javascript google-chrome google-chrome-extension contextmenu