How can I set up a context menu in Google Chrome so that all of the menu are top level?
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 li开发者_开发知识库ke 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});
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.
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.
精彩评论