Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1250 How do I set a delay between two statements?

irt.org | Knowledge Base | JavaScript | Timeout | Q1250 [ previous next ]

Q1250 How do I set a delay between two statements?

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...
}

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.