使用executeScript执行popup.html中的函数
所以,我尝试使用 executeScript 来执行 popup.html 的函数。
这就是我想要做的:
function atacar () {
$(document).ready(function () {
$("#target_attack").click();
});
}
function apoiar () {
$(document).ready(function () {
$("#target_support").click();
});
}
function enviar_comando (tipo) {
chrome.windows.getCurrent(function(win) {
chrome.tabs.getAllInWindow(win.id, function(tabs) {
for (i = 0; i < tabs.length; i++) {
if (tipo == "ataque") chrome.tabs.executeScript(tabs[i].id, { code: "atacar();" });
else if (tipo == "apoio") chrome.tabs.executeScript(tabs[i].id, { code: "apoiar();" });
}
});
});
}
看看这些行:
if (tipo == "ataque") chrome.tabs.executeScript(tabs[i].id, { code: "atacar();" });
else if (tipo == "apoio") chrome.tabs.executeScript(tabs[i].id, { code: "apoiar();" });
我正在尝试执行 popup.html 的一个名为 atacar() 和 apoiar 的函数(),但它不起作用。
帮助? :)
so, I'm trying to use executeScript to execute a function of popup.html.
That's what I'm trying to do:
function atacar () {
$(document).ready(function () {
$("#target_attack").click();
});
}
function apoiar () {
$(document).ready(function () {
$("#target_support").click();
});
}
function enviar_comando (tipo) {
chrome.windows.getCurrent(function(win) {
chrome.tabs.getAllInWindow(win.id, function(tabs) {
for (i = 0; i < tabs.length; i++) {
if (tipo == "ataque") chrome.tabs.executeScript(tabs[i].id, { code: "atacar();" });
else if (tipo == "apoio") chrome.tabs.executeScript(tabs[i].id, { code: "apoiar();" });
}
});
});
}
Look at those lines:
if (tipo == "ataque") chrome.tabs.executeScript(tabs[i].id, { code: "atacar();" });
else if (tipo == "apoio") chrome.tabs.executeScript(tabs[i].id, { code: "apoiar();" });
I'm trying to execute a function of popup.html that's called atacar() and apoiar(), but it's not working.
Help? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 atacar() 和 apoiar() 也在 popup.html 中,因此您无法从executeScript 运行它们。
您可以:
Since atacar() and apoiar() are also in popup.html , you can't run them from the executeScript.
You can either: