chrome contextMenus onClick - receiving information on the selected paragraph



  • Let's say there's a list of points on which the function works.

    function func_1 {alert(1)};
    function func_2 {alert(2)};
    function func_3 {alert(3)};
    ...
    

    chrome.contextMenus.create({"title": "item 1", "onclick": func_1});
    chrome.contextMenus.create({"title": "item 2", "onclick": func_2});
    chrome.contextMenus.create({"title": "item 3", "onclick": func_3});
    ...

    What if it's 20? Do you have a separate function for everyone?

    Would you like to know if it was possible to introduce all the paragraphs as a mass? Is it possible to obtain the title of the paragraph that?

    Main objective: to combine all functions into one.



  • Two parameters info and tab - onclick: function(info, tab) are referred to the callback function. The first contains information on the menu (e.g. info.menuItemId), the second contains information on the contribution. Accordingly, one function of the aggregator may be hanged at the callback. For example, the function of clicking information about the menu and the deposit:

    function genericOnClick(info, tab) {
      console.log("item " + info.menuItemId + " was clicked");
      console.log("info: " + JSON.stringify(info));
      console.log("tab: " + JSON.stringify(tab));
    }
    chrome.contextMenus.create({"title": "item 1", "onclick": genericOnClick});
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2