Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Js delay function

    I need a function in js that delay my page before loading for few seconds.
    What's function do I need?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    There is no *synchronous* delay or wait functionality in javascript - but you could try to do something like this:
    Code:
    function fnDelay(iMs){ // iMs=[number TimeInMilliSeconds]
        var
            iStart=new Date;
        while(new Date-iStart<iMs);
    }
    And call that when you need the delay - but I wouldn't be surprised if you got a message that told you that execution of that script might slow the computer down. You usually get those when you try to do potentially nonterminal loops, or loops that will take too much time to execute.



    There is of course the asynchronous setTimeout that you can use, but then your script execution will continue while waiting.
    Last edited by liorean; 04-08-2003 at 04:11 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •