Ada*_*m91 5 javascript google-chrome google-chrome-extension
在我的 中background.js,当加载期间 URL 匹配时,它会加载 ajax。例如,它是 google.com,它会触发 ajax 并收到一些数据。但如何将这些数据发送到我的 popup.html 呢?
我尝试过chrome.runtime.sendMessage,但我不明白。参数发送到哪个文件?
我很困惑。
当您通过 发送数据时chrome.runtime.sendMessage,您将能够通过监听onMessage事件在弹出窗口中获取它。
当你像这样从background.js发送消息时,
chrome.runtime.sendMessage({msg: 'hello there'});
Run Code Online (Sandbox Code Playgroud)
你可以在 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
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5439 次 |
| 最近记录: |