V
V
Vahe2015-12-01 14:35:33
JavaScript
Vahe, 2015-12-01 14:35:33

Chrome extension contextMenus Api can't add OnClick handler?

I am trying to create a chrome extension. Currently I'm going to create a context menu for my extension that will do something when I click on it. So, following Google documentation I create a context menu.

chrome.runtime.onInstalled.addListener(function() {
  var context = "selection";
  var title = "Google for Selected Text";
  var id = chrome.contextMenus.create({"title": title,
                                       "contexts":[context],
                                        "id": "context" + context
  });  
});

Then I add an OnClick handler to it.
...
onclick : function() { alert("work") }

Are there methods to add other events besides
chrome.contextMenus.onClicked.addListener(onClickHandler);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OVK2015, 2015-12-02
@vahe_2000

Add the handler immediately when creating the context menu element.

downloadItem = chrome.contextMenus.create
(
  {
    id: "utilsExtDownloadMenuItem",
    parentId: rootItem,
    title: "Загрузить...",
    contexts: ["all"],
    onclick: downloadContent
  }, 
  function(){}
);	
........
function downloadContent(info, tab)
{
........
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question