Is there a "delay()" function for JavaScript

I'm wondering if there's a delay() function for JavaScript or something similar. I want to make a script that writes and than writes again, and again but after a surtain time.
Any help would be greately apreciated.

Comments

  • : I'm wondering if there's a delay() function for JavaScript or something similar. I want to make a script that writes and than writes again, and again but after a surtain time.
    : Any help would be greately apreciated.
    :
    :

    use [b]window.setTimeout([/b][italic]function pointer[/italic][b],[/b] [italic]time[/italic][b])[/b].

    [code]
    window.setTimeout(afterDelay, 5000);

    function afterDelay() {
    alert("5 seconds have passed");
    }
    [/code]

    i'm pretty sure [italic]time[/italic] is in milliseconds. note that you HAVE to pass a pointer to a function, not the result of the function, to keep the function from being run before the time delay. that means that you can't put () on the end of the function or it will run when javascript reads the line and try to pass the result of the function to the setTimeout method rather than a pointer to the afterDelay function.

    * (ps: if you have problems with that try just [b]setTimeout[/b] instead of [b]window.setTimeout[/b])
  • : : I'm wondering if there's a delay() function for JavaScript or something similar. I want to make a script that writes and than writes again, and again but after a surtain time.
    : : Any help would be greately apreciated.
    : :
    : :
    :
    : use [b]window.setTimeout([/b][italic]function pointer[/italic][b],[/b] [italic]time[/italic][b])[/b].
    :
    : [code]
    : window.setTimeout(afterDelay, 5000);
    :
    : function afterDelay() {
    : alert("5 seconds have passed");
    : }
    : [/code]
    :
    : i'm pretty sure [italic]time[/italic] is in milliseconds. note that you HAVE to pass a pointer to a function, not the result of the function, to keep the function from being run before the time delay. that means that you can't put () on the end of the function or it will run when javascript reads the line and try to pass the result of the function to the setTimeout method rather than a pointer to the afterDelay function.
    :
    : * (ps: if you have problems with that try just [b]setTimeout[/b] instead of [b]window.setTimeout[/b])
    :
    Thanks.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories