在background.html
:
chrome.tabs.query({active:true, currentWindow:true},function(tabs){
chrome.tabs.sendMessage(tabs[0].id,"target.js");
});
在content.js
:
chrome.extension.onMessage.addListener(function(msg,sender,sendResponse){
if (msg == "target.js"){
extensionID = sender.id;
}
});
但是,它不起作用;
Uncaught TypeError: Cannot read property 'onMessage' of undefined
如何使它正确?