[英]Javascript - Callback inside callback? doesn't work for me with apparently no reason
我正在尝试为Google chrome开发扩展程序,它如何工作? 很好,有一个网站,每次您去那里它都会重定向,但是经过一些尝试它不会重定向,我需要做的是我的扩展程序自动输入该URL,直到它停止重定向。
我懂了:
function update_tab(activeTab){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
activeTab = tabs[0];
}
}
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({"url": "https://Example.com/SiteWanted"});
wait(3000);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
while(activeTab.url === "https://Example.com/SiteIDontWant"){
chrome.tabs.update(activeTab.id,{url:"example.com/SiteWanted"});
update_tab(activeTab);
wait(3000); // i know this function is weird, but it is necessary for the code to work, and yes, i known that using functions to delay the code is not... right
}
});
});
我已经尝试了几乎所有内容,更改了var名称,尝试了chrome.tabs.getCurrent等不同方法,在主函数中移动了代码(update_tab)以及我认为可以帮助我的其他东西,但是我无法解决这个问题,我发现无论我做什么,update_tab中的代码都不会运行,没有它,URL将不会在代码内“更新”,因此While循环将永远运行,并且扩展将进入永远相同的网址。
任何帮助将不胜感激,谢谢:)
如果条件满足,为什么要使用while循环以确保它将永远运行。
if(activeTab.url === "https://Example.com/SiteIDontWant"){
chrome.tabs.update(activeTab.id,{url:"example.com/SiteWanted"});
update_tab(activeTab);
wait(3000); // i know this function is weird, but it is necessary for the code to work, and yes, i known that using functions to delay the code is not... right
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.