0

我正在开发 chrome 扩展。使用上下文菜单选项创建复选框,它在 Ubuntu(O/S) 的 Chrome 浏览器(版本 21.0.1180.15 beta)中运行良好。但复选框在 Windows-XP Chrome 浏览器(版本 23.0.1271.91)中不可见

var contextMenuCallback = function(info, tab) {
  console.log(info);
  console.log(tab);
  // we can do other stuff here.
}

var first_params = {
  "id": "first_id",
  "title": "First",
  "type": "checkbox",
  "checked": true,
  "onclick": contextMenuCallback
};
var second_params = {
 "id": "second_id",
 "title": "Second",
 "type": "checkbox",
 "checked": true,
 "onclick": contextMenuCallback
};  
chrome.contextMenus.create(first_params);
chrome.contextMenus.create(second_params);

给你同样的建议。

4

1 回答 1

1

我在同一个版本,它的工作原理

在此处输入图像描述

您是否检查了上下文菜单的权限,如此处所示。

清单.json

{
  "name": "Context Menu Demo",
  "description": "This gives demo of context menu features",
  "version": "1",
  "permissions": ["contextMenus"],
  "background": {
    "scripts": ["sample.js"]
  },
  "manifest_version": 2,
  "icons":{"16":"screen.png","48":"screen.png","128":"screen.png"}
}

您是否在background.js此处包含代码

var contextMenuCallback = function(info, tab) {
  console.log(info);
  console.log(tab);
  // we can do other stuff here.
}

var first_params = {
  "id": "first_id",
  "title": "First",
  "type": "checkbox",
  "checked": true,
  "onclick": contextMenuCallback
};
var second_params = {
 "id": "second_id",
 "title": "Second",
 "type": "checkbox",
 "checked": true,
 "onclick": contextMenuCallback
};  
chrome.contextMenus.create(first_params);
chrome.contextMenus.create(second_params);

试试这个代码并将屏幕截图发送给我们,以输出您所期望的和缺少的内容?

于 2012-12-01T08:10:41.217 回答