This question already has an answer here:
- Leave a loop after 2 seonds 3 answers
I have a while loop which looks like this:
while(s1 != "#EANF#")
{
iimPlay("CODE:REFRESH");
iimPlay("CODE:TAG POS=1 TYPE=* ATTR=TXT:Contacted:* EXTRACT=TXT")
var s1 = iimGetLastExtract();
}
it will refresh the web page until it finds what it wants. However sometimes it becomes an infinite loop and I want to simply set a timer so that it would break the while loop and carry on. I tried looking at settimeout but couldn't figure out how to do it. I want this while loop to just give up refreshing the web page if it doesn't find what it wants after lets say 3 minutes.
About your question you may define a flag variable and check it in while loop and change its value in timer.
Like :
your while loop:
Your timer function
And somewhere before while loop:
But what I want to say is that I think you have wrong approach in refreshing webpage in a while loop. Maybe you should use Ajax or something. And I might be able to help if you give more information about whole thing you are about to do.
EDIT: This may not be the correct answer...please see comments
You can use a flag that is flipped after 3 minutes in your while loop condition: