22

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?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
mxch
  • 835
  • 2
  • 10
  • 20
  • that is not possible I think, but you can create and delete the items when clicking depending on the element clicked, as described here http://stackoverflow.com/questions/4730843/how-do-i-restrict-context-menus-to-appear-only-for-certain-selected-text-in-a-ch – user1950929 Dec 06 '13 at 15:55

2 Answers2

20

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

animuson
  • 53,861
  • 28
  • 137
  • 147
tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
  • 1
    I posted the same thing earlier, then deleted, because I realized he actually wants to actually add custom HTML to the context menu, and I don't think that's possible. – Jude Osborn Jun 18 '13 at 04:35
  • 8
    I don't think this is a complete answer because the documentation you link to is not clear enough. For example, what parameters should we pass to chrome.contextMenus.create to restrict the menu item to only show up on elements with an ID equal to `"foobar"`? – David Grayson Nov 10 '13 at 00:07
  • 2
    that is not possible I think, but you can create and delete the items when clicking depending on the element clicked, as described here http://stackoverflow.com/questions/4730843/how-do-i-restrict-context-menus-to-appear-only-for-certain-selected-text-in-a-ch – user1950929 Dec 06 '13 at 15:54
5

Use chrome.contextMenus to add the option to right click

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

}, function(){})
SWAPNIL KUWAR
  • 404
  • 4
  • 11