我有一个 Chrome 打包应用程序,但我似乎无法弄清楚如何向其添加上下文菜单。
这是我的 list :
{
"name": "Dialer",
"version": "0.1",
"manifest_version": 2,
"permissions": [
"contextMenus",
"audioCapture"
],
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": {
"128":"icon_128.png"
}
}
这是我的 background.js:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.contextMenus.create ({
title: "%s",
contexts: ["all"],
id: "right-click"
});
});
我做错了什么?当我右键单击时,菜单项没有出现。
谢谢
最佳答案
您可能想查看 Chrome 应用示例,网址为 https://github.com/GoogleChrome/chrome-app-samples/tree/master/context-menu了解其工作原理。
如您所见,上下文菜单将出现在您的 Chrome 应用程序窗口中:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('main.html', {bounds:{ width: 300, height: 300}});
});
chrome.runtime.onInstalled.addListener(function() {
// When the app gets installed, set up the context menus
chrome.contextMenus.create({
title: 'Click on me',
id: 'contextMenuId',
contexts: [ 'all' ]
});
});
不过,如果您要在 Chrome 浏览器中寻找上下文菜单,则可能需要创建一个 Chrome 扩展程序。参见 http://developer.chrome.com/extensions/contextMenus.html
关于javascript - contextMenu 在 Chrome 打包应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20443648/