【发布时间】:2018-04-29 00:54:54
【问题描述】:
我正在开发一个谷歌浏览器扩展。我的目的是将消息从我的 script1.js 发送到 script2.js。这是我在 manifest.json 中写的内容
{
"matches": ["https://www.google.fr/"],
"css": ["styles.css"],
"js": ["script1.js"]
},
{
"matches": ["my_website.html"],
"css": ["styles.css"],
"js": ["script2.js"]
},
这是我在 script1.js 中写的:
chrome.runtime.sendMessage('hello world!!!!!!');
在 script2.js 中:
chrome.runtime.onMessage.addListener(function(response,sender,sendResponse){
警报(响应);
});
我不认为我正在以写入方式进行操作,我认为我必须使用 background.js,但我不知道如何。
非常感谢。
【问题讨论】:
标签: javascript google-chrome google-chrome-extension