ActionsDev
3 replies to this thread. Most Recent
tobiaseichner
27 Feb 2010, 5:51 pm
JavaScript wait command ?
For a small JavaScript app I look for a way to interrupt code execution a few seconds till proceeding. For example:
<code> … document.forms[0].elements[“result”].value = “Anything is okay. Proceeding”; return true; </code>
Between these two commands the script should wait two seconds giving the user the chance to read the text.
I thought about adding a timeout, but maybe there is a more elegant solution (like “sleep” in Perl) ?
But even after having a close look at my reference books, I haven’t found something.
Tobias.
STAR ENTERPRISE - The Universe of powerful Internet and Business Services
Consulting | Software development | Services
Internet: www.starenterprise.com - email@hidden
Joe Billings
27 Feb 2010, 6:32 pmI’m pretty sure timeout() is the equivalent of Perl’s sleep(). It’s a dedicated function built into the API so is likely be the most efficient solution.
Joe
On 27 Feb 2010, at 18:51, tobiaseichner wrote:
For a small JavaScript app I look for a way to interrupt code execution a few seconds till proceeding. For example:
<code> … document.forms[0].elements[“result”].value = “Anything is okay. Proceeding”; return true; </code>
Between these two commands the script should wait two seconds giving the user the chance to read the text.
I thought about adding a timeout, but maybe there is a more elegant solution (like “sleep” in Perl) ?
But even after having a close look at my reference books, I haven’t found something.
Tobias.
tobiaseichner
27 Feb 2010, 7:22 pmThank you. Then I’ll use it.
Tobias.
STAR ENTERPRISE - The Universe of powerful Internet and Business Services
Consulting | Software development | Services
Internet: www.starenterprise.com - email@hidden
waltd
27 Feb 2010, 11:46 pmYou have to set a variable to hold your function, or wrap the function in an anonymous function, then wrap the whole thing in setTimeout().
var foo = function(){
//Do something;
};
window.setTimeout(foo,100);
or
window.setTimeout(function(){
//hello world
},100);
Walter
Freeway user since 1997
