Google chrome extension Chrome扩展[onConnect.addListener,port.postMessage]:如何将消息从扩展发送到安装在任何pc上的扩展?
如标题中所述,我想知道如何向安装在任何计算机上的扩展发送消息 我使用script.js(进入后台页面): 我已经在script.js中创建了Google chrome extension Chrome扩展[onConnect.addListener,port.postMessage]:如何将消息从扩展发送到安装在任何pc上的扩展?,google-chrome-extension,chat,sendmessage,postmessage,Google Chrome Extension,Chat,Sendmessage,Postmessage,如标题中所述,我想知道如何向安装在任何计算机上的扩展发送消息 我使用script.js(进入后台页面): 我已经在script.js中创建了createHTMLNotification(“otherpage.html”)。 在“otherpage.html”中,我有manage_msg.js mnage_msg.js: "when keydow event == 'enter' " -> port.postMessage({text:text, nick:nick, date:date})
createHTMLNotification(“otherpage.html”)
。
在“otherpage.html”中,我有manage_msg.js
mnage_msg.js:
"when keydow event == 'enter' " -> port.postMessage({text:text, nick:nick, date:date});
port = chrome.extension.connect({name: "myport"});
port.onMessage.addListener(function(msg) {
html = '<div class="date">'+msg.backDate+'</div><div class="nick">'+msg.backNick+'</div><div class="testo"></div>';
box_chat = new Element("div",{ class:"box", html:html });
box_chat.inject($("container_boxes"));
box_chat.getElements(".text")[0].set("text", msg.backTxt);
canISetSlider();
});
“when keydow event='enter'->port.postMessage({text:text,nick:nick,date:date});
port=chrome.extension.connect({name:“myport”});
port.onMessage.addListener(函数(msg){
html=''+msg.backDate+''+msg.backNick+'';
box_chat=新元素(“div”,{class:“box”,html:html});
box_chat.inject($(“容器_box”);
box_chat.getElements(“.text”)[0].set(“text”,msg.backTxt);
卡尼塞斯德尔();
});
问题是,这样的消息只到达我,发送者。因此,只有我的
HTMLNotification
会更新。此机制不是为在其他浏览器中向扩展的其他实例发送消息而设计的-它是为在扩展的不同上下文之间发送消息而设计的。如果您希望与插件的其他实例通信,则可能必须使用外部服务器,该服务器将消息从您的计算机传送到其他计算机
"when keydow event == 'enter' " -> port.postMessage({text:text, nick:nick, date:date});
port = chrome.extension.connect({name: "myport"});
port.onMessage.addListener(function(msg) {
html = '<div class="date">'+msg.backDate+'</div><div class="nick">'+msg.backNick+'</div><div class="testo"></div>';
box_chat = new Element("div",{ class:"box", html:html });
box_chat.inject($("container_boxes"));
box_chat.getElements(".text")[0].set("text", msg.backTxt);
canISetSlider();
});