[英]How to get a reference for TITLE, in chrome.contextMenus.create onClick function?
I want to get a reference for chrome.contextMenus.create title property in onClick function. 我想在onClick函数中获取chrome.contextMenus.create title属性的引用。
For example: 例如:
chrome.contextMenus.create({"title": "sometitle", "contexts":["selection"], "onclick": searchSelection});
function searchSelection(info, tab){
var query = "<i want title (sometitle) here>"+info.selectionText;
var url = "http://www.google.com/search?q="+query;
chrome.tabs.create({url: url});
}
I searched, but found no option doing this. 我搜索了,但没有选择这样做。
+1 Question: is there a way to inline edit contextMenu item? +1问题:有没有一种方法可以内联编辑contextMenu项? Or append an editable input field after CM element? 还是在CM元素后附加可编辑的输入字段? I think no, but worth for a question :) 我认为不可以,但是值得提出一个问题:)
There's no existing API method to retrieve information about a given menu item, since this information is rarely needed, and already available to the extension's developer. 没有现成的API方法可检索有关给定菜单项的信息,因为该信息很少需要,并且已经可供扩展程序的开发人员使用。
Here's a general-purpose function to achieve the result: 这是实现结果的通用功能:
/**
* Creates a menu item using chrome.contextMenus.create.
* When the second argument is specified, the click handler receives a
* third argument: The original creation data.
* When the "onclick" property is set in the creationData, the "onclick"
* event does not receive a third parameter.
*
* @param object creationObject Basic creation object
* @param function onclickHandler "click" property of the creationObject
*/
function createMenuItem(creationObject, onclickHandler) {
if (onclickHandler) {
creationObject.onclick = function(onClickData, tab) {
onclickHandler(onClickData, tab, creationObject);
};
}
return chrome.contextMenus.create(creationObject);
}
// Usage:
createMenuItem({"title": "sometitle", "contexts":["selection"]}, searchSelection);
function searchSelection(info, tab, creationData) {
var query = "<i want title " + creationData.title + " here>" + info.selectionText;
var url = "http://www.google.com/search?q=" + query;
chrome.tabs.create({url: url});
}
And no, there is no way to add an inline-editable menu item (the only available options are mentioned in the documentation, chrome.contextMenus.create
). 而且,没有办法添加可在线编辑的菜单项( 文档chrome.contextMenus.create
中提到了唯一可用的选项)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.