3
Answers

Wait until another thread is working in jQuery

Here, I am waiting for html button element from the popup iframe window. When a popup is open then my block of code will fire the click event on time and it's working fine, but my query is wanting to wait until not get button.
 
I have used the nested function calling with timeout thread, so when I call then work, but don't wait and go to the next task.
  1. setPrint();   
  2. function setPrint() {   
  3.    setTimeout(function () {   
  4.       var btnprint = null;   
  5.       var frame = $('#WindowFadeiFrame').get(0).contentDocument;   
  6.       var btn = $('#btn', frame);   
  7.       if (btn.length == 0) {   
  8.          btnprint == null   
  9.          console.log('not found');   
  10.       }   
  11.       else {   
  12.          btn.click();   
  13.          btnprint = btn;   
  14.          console.log('found now');   
  15.       }   
  16.       if (btnprint == null) {  
  17.          setPrint(); }   
  18.    }, 100);   
  19. }
Answers (3)
1
Mehul Prajapati

Mehul Prajapati

NA 65 1.5k 7y
function setPrint(callback) {
var obj = setInterval(function () {
var frame = $('#WindowFadeiFrame').get(0).contentDocument;
var btn = $('#btn', frame);
if (btn.length == 0) {
console.log('not found');
}
else {
btn.click();
console.log('found now');
clearInterval(obj);
callback();
}
}, 100);
}
setPrint(callback)
function callback() {
// write all your code here which need to be executed after finding the control from iframe
alert('');
}
0
Mehul Prajapati

Mehul Prajapati

NA 65 1.5k 7y
setPrint();
alert("hi");
 
i don't want to call alert('hi) until not get button and click it.
setPrint() is nested function, so it call itself until not get button. 
0
Laxmidhar Sahoo

Laxmidhar Sahoo

NA 2.3k 1.4k 7y
sir try to provide 1000 insted of 100