admin管理员组文章数量:1418592
In my background.js
, it had ajax loaded when a URL is matched during the on-load. For instance, it's google and it fire an ajax and recieved some data. But how to send those data to my popup.html?
I tried chrome.runtime.sendMessage
but I don't get it. The param send to which file?
I'm confused.
In my background.js
, it had ajax loaded when a URL is matched during the on-load. For instance, it's google. and it fire an ajax and recieved some data. But how to send those data to my popup.html?
I tried chrome.runtime.sendMessage
but I don't get it. The param send to which file?
I'm confused.
Share Improve this question asked Sep 1, 2014 at 15:40 Adam91Adam91 831 silver badge9 bronze badges2 Answers
Reset to default 3when you send data via chrome.runtime.sendMessage
, you will be able to get it in your popup by listening to onMessage
events.
when you send a message from background.js like this,
chrome.runtime.sendMessage({msg: 'hello there'});
you can get it in a js file loaded by popup.html:
chrome.extension.onMessage.addListener(function(message, messageSender, sendResponse) {
// message is the message you sent, probably an object
// messageSender is an object that contains info about the context that sent the message
// sendResponse is a function to run when you have a response
});
See here and here
Can you edit your question to include your manifest.json? That's often very helpful when making suggestions.
Assuming that your popup.html is part of a content script, you need to use chrome.tabs.sendMessage to send messages from the background page to content scripts.
Also consider using chromeps for simple pubsub style message propagation throughout your extension without having to worry about when to use chrome.runtime
vs chrome.tabs
.
本文标签: javascriptsend data from backgroundjs to popuphtmlStack Overflow
版权声明:本文标题:javascript - send data from background.js to popup.html - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287438a2651584.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论