Javascript Chrome 扩展:将功能附加到右键菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5193350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome-extension: Append functions to right click menu
提问by Skizit
How would I append functions to the right click menu in the browser? E.g something
appended to the right click menu which does function dosomething()
which is located in my extension.
我如何将功能附加到浏览器的右键菜单中?例如,something
附加到右键单击菜单中,该菜单执行dosomething()
位于我的扩展程序中的功能。
采纳答案by Skizit
Found out how, using the contextmenu API http://developer.chrome.com/extensions/contextMenus.html
了解如何使用上下文菜单 API http://developer.chrome.com/extensions/contextMenus.html
回答by Anurag-Sharma
I made simple extenstion using the contextMenu API - link
Hope this works well as an example.
我使用 contextMenu API 进行了简单的扩展 -链接
希望这可以很好地作为示例。
manifest.json -
manifest.json -
{
"manifest_version": 2,
...
...
"permissions": [
"contextMenus",
"tabs"],
...
...
"background": {"page": "background.html"}
}
main.js -
main.js -
searchUrbanDict = function(word){
var query = word.selectionText;
chrome.tabs.create({url: "http://www.urbandictionary.com/define.php?term=" + query});
};
chrome.contextMenus.create({
title: "Search in UrbanDictionary",
contexts:["selection"], // ContextType
onclick: searchUrbanDict // A callback function
});
For more information on different context types - link
有关不同上下文类型的更多信息 -链接