开发者

How to add a custom item into the chrome context menu?

开发者 https://www.devze.com 2023-01-05 00:44 出处:网络
Is there any API to be used to add a custom item into the chrome context menu? For example: Now, I wanna add a \"send to ...\" item to context menu(right click), wh开发者_如何转开发en it is clicked

Is there any API to be used to add a custom item into the chrome context menu?

For example:

Now, I wanna add a "send to ..." item to context menu(right click), wh开发者_如何转开发en it is clicked the contents selected in the webpage will be sent to someone.

I searched the chrome APIS and found that chrome.experimental.contextMenu is competent for my requirement, however it is experimental API so something like "path_to_chrome.exe --enable-experimental-extension-apis" will be added.

Any other solutions?


Now (for long time) you have an option.

  1. Add this permission to your manifest.json file

    "permissions": ["contextMenus"]
    
  2. Then, something like that will do the trick:

    chrome.contextMenus.create({
      'title' : 'Open this select text %s',
      'contexts' : ['selection'],
      'onclick' : function(info, tab) {
         console.log('Selected link: ' + info.selectionText);
      }
    });
    

Good luck.


Using contextMenu is the one and only way (outside of hacking on the Chromium source), but the API should be graduating from experimental when Google Chrome 6 gets released to the stable channel.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号