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.
setPrint();
function setPrint() {
setTimeout(function () {
var btnprint = null;
var frame = $('#WindowFadeiFrame').get(0).contentDocument;
var btn = $('#btn', frame);
if (btn.length == 0) {
btnprint == null
console.log('not found');
}
else {
btn.click();
btnprint = btn;
console.log('found now');
}
if (btnprint == null) {
setPrint();
}
}, 100);
}
What I have tried:
I have made busy to compile with the loop until not get button, but I got to hang my site.