使用Google Chrome API在JavaScript中传递的函数参数

时间:2015-09-19 16:55:59

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

我在使用Chrome API时遇到问题。具体来说,我似乎无法通过我的上下文菜单onclick函数传递任何内容。

var linkSafetyChild = chrome.contextMenus.create({"title":"Is this link safe?","parentId":linkParent,"contexts":[contexts[2]],"onclick":checkScamAdvisorLink});

调用函数:

function checkScamAdvisorLink(info, tab){   alert(info.mediaType);
var searchString = "http://www.scamadviser.com/check-website/";
alert(info.linkURL);
var siteToCheck = convertURLToSearchableString(info.linkURL);
var finalString = searchString.concat(siteToCheck); }

但是当我尝试使用alert(info.mediaType)和alert(info.linkURL)访问info对象时,都返回undefined。如何将此信息传递给checkScamAdvisorLink?

以上摘录来自清单中指定的launch.js.

的manifest.json:

{
"manifest_version": 2,

"name":"Hi-Brite Informational Assistant",
"description": "This extension provides extended information and performs various helpful actions based on highlighted text. Just kidding, it does nothing",

"version": "0.0.0",

"browser_action": {
    "default_icon": "icon.png",
    "default_popup":"my_popup.html"
},

"permissions": ["activeTab", "https://ajax.googleapis.com/", "contextMenus","tabs"],

"background":{
    "scripts":["launch.js"]
},

"content_scripts":[{
        "matches": ["https://www.tineye.com/"],
        "js":["TinyEyeSearch.js"]
}]}

0 个答案:

没有答案