![](/img/trans.png)
[英]what's the type for `info` in the onclick callback in chrome.contextMenus.create?
[英]How to get a reference for TITLE, in chrome.contextMenus.create onClick function?
我想在onClick函數中獲取chrome.contextMenus.create title屬性的引用。
例如:
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});
}
我搜索了,但沒有選擇這樣做。
+1問題:有沒有一種方法可以內聯編輯contextMenu項? 還是在CM元素后附加可編輯的輸入字段? 我認為不可以,但是值得提出一個問題:)
沒有現成的API方法可檢索有關給定菜單項的信息,因為該信息很少需要,並且已經可供擴展程序的開發人員使用。
這是實現結果的通用功能:
/**
* 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});
}
而且,沒有辦法添加可在線編輯的菜單項( 文檔chrome.contextMenus.create
中提到了唯一可用的選項)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.