Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension: add option to right click menu when clicking certain HTML element

I want to create a Chrome extension that adds an option to the right click menu when the user right clicks a certain HTML element (for example a DIV with a known ID).

I would use this to add an option when the user right clicks a tweet on Twitter.com and that option would call a REST service.

Is this posible with a regultar Chrome extension?

like image 510
mxch Avatar asked Jul 13 '12 01:07

mxch


People also ask

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 enable right click on my HTML page?

Another easy way to enable the right-click menu on any webpage is by using a simple code snippet. For that, navigate to the target webpage and copy + paste the following line of code in the address bar: javascript:void(document. oncontextmenu=null); and hit Enter.

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

Yes, these are called Context Menus. You can find the docs for those here: https://developer.chrome.com/extensions/contextMenus

like image 167
tomdemuyt Avatar answered Oct 12 '22 21:10

tomdemuyt


Use chrome.contextMenus to add the option to right click

chrome.contextMenus.create({
    title: 'test',
    onclick: function(e){
        console.log(e)
    }

}, function(){})
like image 28
SWAPNIL KUWAR Avatar answered Oct 12 '22 21:10

SWAPNIL KUWAR