|
Q990 setTimeout doesn't pause the execution of my code, how can I pause the execution of my code?
irt.org | Knowledge Base | JavaScript | Timeout | Q990 [ previous next ]
Q990 setTimeout doesn't pause the execution of my code, how can I pause the execution of my code?
It depends how you write your code:
<script language="JavaScript"><!--
function myFunction1() {
var now1 = new Date();
setTimeout('myFunction1()',10000);
var now2 = new Date();
alert('difference = ' + (Date.parse(now2) - Date.parse(now1)));
}
myFunction1();
//--></script>
|
will always trigger the alert message 0 milliseconds later, whereas the following:
<script language="JavaScript"><!--
var now1 = now2 = '';
function myFunction1() {
now1 = new Date();
setTimeout('myFunction2()',10000);
}
function myFunction2() {
now2 = new Date();
alert('difference = ' + (Date.parse(now2) - Date.parse(now1)));
myFunction1();
}
myFunction1();
//--></script>
|
will always trigger the alert 10000 milliseconds later.
|
|
Copyright © 1996-2009 irt.org, All Rights Reserved.