Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1250 How do I set a delay between two statements?

You are here: irt.org | FAQ | JavaScript | Timeout | Q1250 [ previous next ]

There is no pause or sleep in JavaScript.

Split your function and call the second one with a setTimeout

// before:

function callTwoStatements() {
   statement1...
   for (i=0;i<10000;i++) ; // do nothing but eat CPU
   statement2...
}

// after:

function callStatement1() {
   statement1...
   setTimeout('callStatement2()',2000); // delay 2 seconds
}
function callStatement2() {
   statement2...
}

©2018 Martin Webb