Click here to Skip to main content
15,920,603 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 1-Jan-18 19:26pm

1 solution

use setInterval() [^] method to check for the element once the element is found the clear the setInterval object using clearInterval() [^] method. this will eliminate the looping to create delay which is a very bad idea
 
Share this answer
 
Comments
[no name] 2-Jan-18 1:43am    
@karthik Bangalore, setInterval is also not wait until not get a button. i want that: first call setprint() and next another code. but must call another call after getting response of setprint().
Karthik_Mahalingam 2-Jan-18 2:19am    
setInterval is used to check the object in a periodic interval.
[no name] 2-Jan-18 2:41am    
setPrint();
alert("hi");

here,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.
Karthik_Mahalingam 2-Jan-18 2:50am    
so you want to call alert, only when the button is found in the iframe, correct?
[no name] 2-Jan-18 2:42am    
setInterval is separate thread. so i can't handle it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900