contextMenu onclick事件未触发

时间:2015-01-20 10:13:24

标签: javascript google-chrome google-chrome-extension

- 已解决[见评论部分] -

我遇到contextMenu onclick事件的问题。

当我尝试从我从外部API请求的JSON动态创建菜单时。只有在重新加载扩展程序并且已创建onclick后,contextMenu事件才会触发。

var data = firstext.db.getJSON("list");
for ( list in data ) {
    chrome.contextMenus.create({"title": list.name, "contexts": ["all"], "onclick": function(data) { console.log('clicked: ' + list.id);}});
}

清单:

{
"version": "0.1.3",
"manifest_version": 2,
"default_locale": "en",
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"icons" : {
    "16" : "assets/images/on16.png",
    "24" : "assets/images/on24.png",
    "48" : "assets/images/on48.png",
    "128" : "assets/images/on.png"
},
"browser_action" : {
    "default_popup" : "popup.html",
    "default_icon" : "assets/images/off24.png"
},
"background": {
    "scripts": ["assets/js/library.js", "assets/js/background.js"]
},
"permissions": [
    "contextMenus",
    "tabs",
    "storage",
    "unlimitedStorage",
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
]}

0 个答案:

没有答案