我正在学习Chrome扩展程序并尝试构建以下上下文菜单,该菜单应在选择文本时打开带有指向维基百科的链接的弹出窗口。这是我的代码
的manifest.json
{
"manifest_version": 2,
"name": "Wikit",
"description": "Search Wikipedia on the go!",
"version": "1.0",
"icons" : {
"16":"icon16.png",
"48":"icon48.png",
"128":"icon128.png"
},
"background": {
"scripts": ["eventPage.js"],
"persistent" : false
},
"permissions" : [
"tabs",
"contextMenus"
]
}
eventPage.js
var menuItem = {
"id" : "wikit",
"title" : "Wikit",
"contexts" : [ "selection" ]
}
chrome.contextMenus.create(menuItem);
function fixedEncodeURI(str) {
return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
chrome.contextMenus.onClicked.addListener(function(clickData) {
if (clickData.menuItemId == "wikit" && clickData.selectionText) {
var wikiUrl = "https://en.wikipedia.org/wiki/"
+ fixedEncodeURI(clickData.selectionText);
var createData = {
"url" : wikiUrl,
"type" : "popup",
"top" : 5,
"left" : 5,
"width" : screen.availWidth / 2,
"height" : screen.availHeight / 2
};
chrome.windows.create(createData, function() {
});
}
})
当我选择文本并单击Wikit时,它不会打开新的弹出/选项卡/页面。我做错了什么?