Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 709
Skizit Avatar asked Mar 04 '11 11:03

Skizit


People also ask

How do I add a custom right-click menu to my website?

To do this, we will use two properties pageX and pageY of the mouse click event which will give us the coordinates where the right button was clicked. We will hide the context menu on the mouse button click if it is already being displayed. JavaScript code: HTML.

How do I change the right-click menu in Chrome?

Right-click your Google Chrome shortcut and click Properties. Note: You have to put a space between chrome.exe before the code. It's two hyphens, and not a long em dash (–). Click OK, launch Chrome, and you'll see the right-click context menu is back to normal.

How do I customize the right-click menu in HTML?

To make this HTML menu visible when right-clicking in the browser, we need to listen for contextmenu events. We can bind the event listener directly on the document or we can limit the area that a user can right-click to see the custom context menu. In our example, the area for right-click is the entire body element.

How do I add a context menu to Chrome?

Use the chrome. contextMenus API to add items to Google Chrome's context menu. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.


2 Answers

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

like image 63
Anurag-Sharma Avatar answered Oct 07 '22 22:10

Anurag-Sharma


Found out how, using the contextmenu API https://developer.chrome.com/docs/extensions/reference/contextMenus/

like image 38
Skizit Avatar answered Oct 07 '22 20:10

Skizit