In my background.js
,当加载期间 URL 匹配时,它会加载 ajax。例如,它是 google.com,它会触发 ajax 并收到一些数据。但如何将这些数据发送到我的 popup.html 呢?
I tried chrome.runtime.sendMessage
但我不明白。参数发送到哪个文件?
我很困惑。
当您通过发送数据时chrome.runtime.sendMessage
,您将能够通过收听来在弹出窗口中获取它onMessage
events.
当你像这样从background.js发送消息时,
chrome.runtime.sendMessage({msg: 'hello there'});
你可以在 popup.html 加载的 js 文件中获取它:
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 https://developer.chrome.com/extensions/runtime#method-sendMessage and here https://developer.chrome.com/extensions/runtime#event-onMessage
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)