Need help for loop like sleep or wait function

Discussion in 'JavaScript' started by Alexisnicholson, Nov 22, 2013.

  1. #1
    Want to create delay in javascript for loop like sleep or wait function
    note:- setTimeout() not working
    for(var start = 1; start < 10; start++) {

    //wait for some minute

    }
     
    Alexisnicholson, Nov 22, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Define 'not working' -- and note, javascript is single threaded and single instance, so hanging scripting like that will hang the entire browser... to the point that if you are waiting MINUTES the browser will actually throw an error if you don't release execution.

    That's why you should set a timeout event in the first place! So scripting can release execution back to the browser.
     
    deathshadow, Nov 22, 2013 IP
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #3
    Why not create a layer over the page with css and then create a setTimeout function to remove the layer after a set amount of seconds?
     
    HuggyStudios, Nov 28, 2013 IP