Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

javascript - Chrome-extension: Append functions to right click menu

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.

question from:https://stackoverflow.com/questions/5193350/chrome-extension-append-functions-to-right-click-menu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I made simple extenstion using the contextMenu API - link
Hope this works well as an example.

manifest.json -

{
  "manifest_version": 2,
  ...
  ...
  "permissions": [
      "contextMenus", 
      "tabs"],
  ...
  ...
  "background": {
    "page": "background.html",
    "scripts": ["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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...