How can I set up a context menu in Google Chrome so that all of the menu are top level?

余生颓废 提交于 2019-12-06 04:45:46

问题


I am working on a Google Chrome extension and I have set up several right click context menu items. I see that there is something in the syntax for adding a menu item which allows you to choose a parentID, but I don't see anything that would allow you to choose to have all the menu items as top level items.

Here's an example of my plugin with a single top level menu item and then several sub menu items:

I'd like to bring those out to the top level because I use them a lot. This is the code that I have so far, but I can't figure out how to pull them all up a level:

chrome.contextMenus.create({'title': 'Send URL to Quicksilver',
                            'contexts': ['all'],
                            'onclick': sendToQuicksilver});

chrome.contextMenus.create({'title': 'Send File to Quicksilver',
                            'contexts': ['all'],
                            'onclick': sendFileToQuicksilver});


chrome.contextMenus.create({'title': 'Quick Download',
                            'contexts': ['all'],
                            'onclick': quickDownload});


chrome.contextMenus.create({'title': 'Edit in Textmate',
                            'contexts': ['all'],
                            'onclick': editInTextmate});


chrome.contextMenus.create({'title': 'Open Project in Textmate',
                            'contexts': ['all'],
                            'onclick': editProjectInTextmate});

回答1:


It's not possible, you are allowed to create only one top level menu per extension.

From specs:

You can create as many context menu items as you need, but if more than one from your extension is visible at once, Google Chrome automatically collapses them into a single parent menu.




回答2:


Serg is right, it isn't possible with Chrome's menu. If you are willing to replace the whole right-click menu it is possible:

http://davidwalsh.name/mootools-context-menu

There are several other menu replacement plug-ins/frameworks.

Have you considered just adding a menu-bar to the pages you are interested in?

http://www.hongkiat.com/blog/drop-down-menu-30-free-scripts-to-enhance-header-navigation/

You could have one click access to the menu items you want.



来源:https://stackoverflow.com/questions/7721230/how-can-i-set-up-a-context-menu-in-google-chrome-so-that-all-of-the-menu-are-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!