0
我试图从background.js
发送消息到contentscript文件,script.js
。下面是代码内容广告后台脚本文件之间没有传递消息
的script.js
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
// alert('Message from View:\n'
// + JSON.stringify(msg));
alert(msg);
if (msg.method === 'sendHTML')
{
//process the return code
sendResponse({ data: "Your DOM is here"});
}
});
background.js
chrome.browserAction.onClicked.addListener(function (tab)
{
// var url = tab.url.toLowerCase();
// if(url.indexOf("middlecoin") == -1)
// alert("You are not on MiddleCoin Page");
// else
// chrome.tabs.create({ url: loaderURL + tab.id });
alert("Clicked Call");
chrome.runtime.sendMessage({method: "sendHTML"}, function(response) {
alert(response.data);
});
});
警报response.data)
不会被调用。我在哪里做错了?
让我告诉任何HTML文件在整个延伸件