找出在 Chrome 扩展中发送响应的选项卡
在后台脚本中,我向每个选项卡发送请求。我的问题是如何在回调函数中获取响应来源的选项卡?由于 sendRequest 是异步的,因此 tab.id 不能在回调中使用。
for (var i = 0, tab; tab = tabs[i]; i++) {
chrome.tabs.sendRequest(tab.id, {play:0}, function(response) {
// do something here
// how do i get the tab.id from which the response come from?
});
}
In the background script, I send requests to each tab. My question is how do I get the tab from which the response came from in the callback function? Since sendRequest is asynchronous, the tab.id cannot be used in the callbock.
for (var i = 0, tab; tab = tabs[i]; i++) {
chrome.tabs.sendRequest(tab.id, {play:0}, function(response) {
// do something here
// how do i get the tab.id from which the response come from?
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建闭包:
You need to create closure: