4

我正在使用chrome.tabs.executeScript将脚本注入选项卡。它的最后一个参数是一个回调函数,将被调用The result of the script in every injected frame.。如何让我的脚本返回结果?我尝试在我的 js 末尾添加一个简单的 return 语句,但没有返回任何内容。

4

1 回答 1

5

正如 RobW 纠正我的那样,函数不是必需的,只需确保所需的数据是最后一个表达式,当然这是 JSON 可序列化的。

chrome.tabs.executeScript(tabId,
  {code:"document.charset"},
  function(results){
     // results[0] will now contain the charset for the page in question
});
于 2013-05-24T05:19:27.023 回答