关于 chrome.tabs.executeScript( id,details, callback) [英] about chrome.tabs.executeScript( id,details, callback)

查看:22
本文介绍了关于 chrome.tabs.executeScript( id,details, callback)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个函数有一个回调,比如function(array of any result){...};

This function has a callback like function(array of any result) {...};

但我不知道结果是什么意思.

But I don't know what is the result means.

例如

chrome.tabs..executeScript(null,
   {code:"var x = 10"},
   function(){});

如何将x返回给回调?

推荐答案

脚本的结果是最后一个被计算的表达式.因此,在您的示例中,您可以使用:

The result of a script is the last expression being evaluated. So in your example you could use:

chrome.tabs.executeScript( null, {code:"var x = 10; x"},
   function(results){ console.log(results); } );

这会将[10]记录到扩展的控制台.

This will log [10] to the extension's console.

results 实际上是一个值数组,因为如果页面有多个框架,您可以指定脚本应该注入到每个框架中并获取所有注入的结果.请参阅executeScript 的规范.如果您不指定 allFrames: true,则 results 将始终是一个单元素数组.

results is actually an array of values because if the page has more than one frame you can specify that the script should be injected in each one of them and get the result of all injections. See the specification for executeScript. If you don't specify allFrames: true, then results will always be a single element array.

这篇关于关于 chrome.tabs.executeScript( id,details, callback)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆