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间通信
不提。
本文介绍了Chrome浏览器扩展中不同组件间的通信机制,包括popup与background页面之间的消息传递方式及其实现代码示例。同时,文章也提及了content脚本与popup、background间通信的建议。
2427

被折叠的 条评论
为什么被折叠?



