I am trying to create an extension that will search the selected word into a dictionary.
(我正在尝试创建一个扩展程序,它将选择的单词搜索到词典中。)
I am trying to get the selected text into a variable in JavaScript but it's not working.(我正在尝试将选定的文本转换成JavaScript中的变量,但无法正常工作。)
Here is the code:(这是代码:)
var search= {
"id": "searchurl",
"title": "Search on dictionary",
"contexts": ["selection"]
};
chrome.contextMenus.create(search);
chrome.contextMenus.onClicked.addListener(function(clickData){
"use strict";
if (clickData.menuItemId === "searchurl" && clickData.selectionText){
var urlkey = Document.getSelection().toString();
alert(urlkey);
}
});
I have included jquery to make it work on chrome.
(我包括了jquery,使其可以在chrome上使用。)
ask by Abid translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…