可能重複:
Port error while changing chrome extension from manifest v1 to v2鉻附加組件在上下文菜單中沒有顯示
我想開發我的網站的插件。我的用戶將需要能夠在任何網頁右鍵點擊任何超鏈接,然後點擊,將帶他們到我的網站上執行操作的Chrome瀏覽器右鍵菜單中的鏈接。
我的插件已完成,但每次我嘗試測試它,鏈接不會出現在Chrome上下文菜單時,超鏈接是reght-點擊。
這裏是我的文件:
manifest.jason
{
"manifest_version": 2,
"background_page": "background.html",
"description": "Decrypt Short URLs.",
"icons": {
"128": "icon-128.png",
"16": "icon-16.png",
"48": "icon-48.png"
},
"minimum_chrome_version": "8.0.0.0",
"name": "xxxx.xxx",
"permissions": [ "http://*/*", "https://*/*", "tabs", "contextMenus" ],
"version": "1.0"
}
background.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function handleClick() {
return function(info, tab) {
var url = 'http://xxx.xxx/api.php?url=' + info.linkUrl + '&source=chromeextension'
// Create a new tab to the results page
chrome.tabs.create({ url: url, selected:true });
};
};
chrome.contextMenus.create({
"title" : "Decrypt this Link",
"type" : "normal",
"contexts" : ["link"],
"onclick" : handleClick()
});
</script>
</body>
我會明白任何幫助。
您應該在使用清單v。2時將腳本(函數handleClick()')提取到單獨的文件中。 – chaohuang
也嘗試使用'function handleClick(info,tab)'而不是'function handleClick(){return函數(info,tab){}}' – chaohuang
'chrome'的[document](http://developer.chrome.com/extensions/tabs.html#method-create)中找不到參數'selected:true' .tabs.create' – chaohuang