Page 1 of 1

sleep func

Posted: Sun Oct 23, 2011 12:30 pm
by motiksir
[*]
hiĀ 
i try to do a virtual chat..
and i want to do a sleep func before that i accept answer..
for example:
you:hi
(sleep 3 sec)//there is a label that write "virtual chat typing"
virtual chat:hi my friend
how i can do sleep func in javascript...
I try to do SetTimeout.. but when appear the status message, the message of virtual chat appear without wait..

Re: sleep func

Posted: Sun Oct 23, 2011 2:05 pm
by twinedev
If you are trying to use the SetTimeout() in javascript like you use sleep() in PHP, that is where the problem is.

Check out this page for explanation and examples of how it works:

http://www.w3schools.com/js/js_timing.asp

-Greg

Re: sleep func

Posted: Thu Oct 27, 2011 12:37 pm
by motiksir
function ContactingOn(){
$("#statusLabel").html("<div id='typing'>adi type..</div>");
setTimeout("$("#statusLabel").html("");", 3000); //delete "adi type..."after 3 second

//i need that to be a sleep of 3 sec

addLineAgent("mkasdmlasdmasdkl"); //func that add string to frame


$("#statusLabel").html("<div id='typing'>adi type..</div>");
setTimeout("$("#statusLabel").html("");", 3000); //delete "adi type..."after 3 second

//i need that to be a sleep of 3 sec

addLineAgent("mkasdmlasdmasdsasdasddsasaddsadsasdkl");
}


the problem his that it continue in the program without wait 3 sec..