设置超时功能在 chrome 扩展程序弹出窗口.js问题
setTimeout function in chrome extension popup.js issues
我有一个弹出窗口.js文件,其中包含一系列函数。我正在尝试运行一个设置为在创建新选项卡时运行的函数,但延迟很短。这是一个函数示例和我尝试过的解决方案。
// function.
function foo_bar()
{
// some ajax call.
}
// try 1
setTimeout(foo_bar,1000);
EDIT:// executed without delay.
// try 2
setTimeout(function(){
//some ajax call.
},1000)
EDIT:// executed without delay.
// try 3
setTimeout(function(){
foo_bar();
},1000)
EDIT: // didn't seem to execute.
// try 4 and 5
window.addEventListener('load',foo_bar());
window.addEventListener('DOMContentLoaded',foo_bar());
// no delay takes place. The function completes before the page even loads.
// try 6
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {...});
// used the status from here to wait till page load is complete.
//problem with this is that sometimes the status doesn't get updated.
// try 7
// tried to delay the php script by using sleep(2), but ajax call would never complete.
谁能帮忙?不确定它是否有帮助,但脚本未定义为背景或内容。
编辑:更多细节。调用的函数正在执行对远程服务器的 ajax 调用,然后基于数据,使用 chrome.tabs.executeScript 操作新选项卡登陆的页面。唯一的问题是,页面有一半时间没有准备好。
尝试 4 和 5 应该是:
window.addEventListener('load',foo_bar);
window.addEventListener('DOMContentLoaded',foo_bar);
没有发生延迟,因为您以内联方式调用它们。
相关文章:
- 构建JS测试,警报窗口重复上一个Q,而不是问下一个Q
- 在新窗口上使用d3.js
- 如何解决'窗口未定义'终端上的节点JS出错
- 在highcharts.js中向点弹出窗口动态添加文本
- 全局窗口热键在最小化chrome窗口时调用js函数
- 打开“;检查元件”;窗口通过JS
- 在Backbone.js中为窗口对象指定变量
- 如何在传单.js中显示每个choropleth弹出窗口的唯一名称和URL
- JS-窗口宽度函数不起作用
- 可以在调整窗口大小时重新调整stellar.js的元素偏移量
- 自定义警报/弹出窗口和保持JS引擎
- 设置超时功能在 chrome 扩展程序弹出窗口.js问题
- 重定向至“其他窗口JS”
- 弹出窗口.js 未在 Chrome 扩展程序中的 Popup 的头部标签中执行.html Popup
- 无法将消息从 Chrome 扩展程序中的弹出窗口.js发送到后台.js
- 添加一个按钮,用于关闭带有弹出窗口.js的弹出窗口
- 如何在后台.js和弹出窗口.js之间进行通信
- Chrome扩展:访问变量的背景.js从弹出窗口.js
- Chrome 扩展 js:在后台.js和弹出窗口.js之间共享功能
- 引导弹出窗口- JS触发器