chrome扩展通信
popup与background通信
popup.js
chrome.runtime.sendMessage('Hello', function(response){
document.write(response);
});
background.js
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
if(message == 'Hello'){
sendResponse('Hello from background.');
}
});
实际上:
background.js
function co(){
alert("hello");
}
popup.js
var bg = chrome.extension.getBackgroundPage();
bg.co();
content与popup间通信
不建议。
content与background间通信
不提。