jQuery Javascript在继续执行代码之前等待iframe加载
我正在使用javascript/jQuery和iFrames开发一个webbrowser自动化项目。问题是代码必须等待iframe加载后才能继续执行jQuery Javascript在继续执行代码之前等待iframe加载,javascript,jquery,iframe,browser-automation,Javascript,Jquery,Iframe,Browser Automation,我正在使用javascript/jQuery和iFrames开发一个webbrowser自动化项目。问题是代码必须等待iframe加载后才能继续执行 // set value on iframe input on page 1 $('#csi').contents().find('#inputonpage1').val('hello world'); // click the send button $('#csi').conten
// set value on iframe input on page 1
$('#csi').contents().find('#inputonpage1').val('hello world');
// click the send button
$('#csi').contents().find('#sendbuttononpage1').trigger('click');
// here must wait until the iframe loads it's 'new' page
?
// set value on another field on page 2
$('#csi').contents().find('#inputonpage2').val('hello world again');
// click a button...
$('#csi').contents().find('#sendbuttononpage2').trigger('click');
// wait to load... and continue on page 3... 4... 5... etc...
.
等等
我已经读过有关$.load函数回调的所有内容,但是我需要一些东西来防止在iframe准备就绪之前执行下一行代码。不止一次,就像我在其他帖子中看到的那样
我正在尝试使用全局标记iframe状态。。。比如:
var isready = false;
$(document).ready(function(){
$("#csi").load(function(){
isready=true;
});
$("#buttonstart").click(function(){
// fill fields and click button...
// start wait function
// fill fields and click button...
});
});
function wait(){
while(!isready){
// thread hangs here....
}
isready=false; // disarms
}
thx,javascript是单线程的,您的while循环将使浏览器崩溃。只要将加载后需要运行的所有内容都放在加载的回调中就行了。我猜您的意思是开始根据需要嵌套所有加载?我的代码很快就会变得一团糟。在运行下一行代码之前,没有办法告诉javascript等待x个时间或直到某个特定条件。嵌套和/或也使用嵌套的延迟对象将是唯一的方法。@KevinB怎么办?