I'm working on a webbrowser automation project using javascript/jQuery and iFrames. The problem is that the code must wait for the iframe to load before continue it's execution.
// 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...
.
and so on...
I've read about the $().load function callback an all those stuff, but I need something to prevent the execution of the next line of code before the iframe it's ready. NOT ONLY ONCE as I've seen in all other posts.
I'm trying to use a global to flag the iframe status... something like:
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,