Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension 从chrome扩展中的后台脚本调用内容脚本中的函数_Google Chrome Extension - Fatal编程技术网

Google chrome extension 从chrome扩展中的后台脚本调用内容脚本中的函数

Google chrome extension 从chrome扩展中的后台脚本调用内容脚本中的函数,google-chrome-extension,Google Chrome Extension,我试图从background.js调用content.js中的函数。我该怎么做 Content.js function foo() { alert("Hi"); } Background.js main(); 你不能。这些是独立的过程。用它代替。是的,我试过了,但运气不好(我是新手)。有关于如何使用消息传递的提示吗?请检查。还可以使用devtools通过设置断点、检查变量、单步执行代码来调试chrome扩展的各个部分。

我试图从background.js调用content.js中的函数。我该怎么做

Content.js

function foo() {
    alert("Hi");
}
Background.js

main();

你不能。这些是独立的过程。用它代替。是的,我试过了,但运气不好(我是新手)。有关于如何使用消息传递的提示吗?请检查。还可以使用devtools通过设置断点、检查变量、单步执行代码来调试chrome扩展的各个部分。