Javascript 如何使用SetTimeout在Google Chrome扩展中引入时间延迟

Javascript 如何使用SetTimeout在Google Chrome扩展中引入时间延迟,javascript,google-chrome-extension,settimeout,Javascript,Google Chrome Extension,Settimeout,我尝试了很多方法,但我还是被难倒了 我需要在下面的代码中引入等待,以防止频繁的页面重新加载 // Need to Introduce 5 Second wait here $$("a[href*='city']")[0].click(); 据我所知,使用SetTimeout应该可以做到这一点,但我无法使语法正常工作 谢谢 函数检查(){ numEnemies=parseInt(document.querySelector(“#tb#b”).textContent); 如果(numEnem

我尝试了很多方法,但我还是被难倒了

我需要在下面的代码中引入等待,以防止频繁的页面重新加载

// Need to Introduce 5 Second wait here
  $$("a[href*='city']")[0].click();
据我所知,使用SetTimeout应该可以做到这一点,但我无法使语法正常工作

谢谢

函数检查(){
numEnemies=parseInt(document.querySelector(“#tb#b”).textContent);
如果(numEnemies<1){
$$([a[href*='train'])[0]。单击();
返回true;
}
返回false;
}
var bool=checkbuys();
如果(!bool){
//需要在这里引入5秒等待
$$([a[href*='city'])[0]。单击();

}
setTimeout(function(){put code here;},5000)
太棒了!谢谢成功了!我如何确认你的答案?它甚至不是答案。这太基本了,不值得费心。