Microsoft Edge | Microsoft Edge 开发
Developing and testing features or extensions for Microsoft Edge
在edge 的扩展开发中,
如何从background 向 sidePanel 发送消息
如果从sidePanel 向 background 发送消息
Developing and testing features or extensions for Microsoft Edge
Hi @mars,
对于发送消息,您可以使用chrome.runtime.sendMessage()。例如:
chrome.runtime.sendMessage({ message: "Hello" });
对应的,要接收消息,您可以使用chrome.runtime.onMessage.addListener()。例如:
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if(request.message === "Hello"){
console.log('Message received.');
};
});
无论是background还是sidePanel都是一样的用法。您需要在background.js和sidePanel.js(文件名仅供参考)中使用。
如果答案是正确的,请点击“接受答案”并点赞。如果您对此答案还有其他疑问,请点击“评论”。
注意:如果您想接收电子邮件通知,请按照我们的文档中的步骤启用电子邮件通知。