Repeat with pause

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ZT.Ph34rl3ss@gmail.com

    Repeat with pause

    Hi there,

    First off thank you for reading.

    I'm trying to get the following to work.
    I want a script that does the following 9 times: jah(urlOne); and then
    1 time: jah(urlTwo); then it should start at the top again.
    There has to be a break in between, thats why i have the wait function
    there.
    Hope anybody can help me because i'm not seeing my mistake and can't
    think clear any more.

    Thank you for reading.

    <script language="javas cript" type="text/javascript">


    var urlOne="message Center.php, msgOne";
    var urlTwo="message Banner.php, msgOne";
    var waitTime="1000" ;

    alert (urlOne);

    function wait(msecs)
    {
    var start = new Date().getTime( );
    var cur = start
    while(cur - start < msecs)
    {
    cur = new Date().getTime( );
    }
    }


    alert (urlOne + " voor de statment");
    jah(urlOne);
    alert (urlOne + " na de statment");
    wait(waitTime);

    </script>



  • Joost Diepenmaat

    #2
    Re: Repeat with pause

    "ZT.Ph34rl3ss@g mail.com" <ZT.Ph34rl3ss@g mail.comwrites:
    Hi there,
    >
    First off thank you for reading.
    >
    I'm trying to get the following to work.
    I want a script that does the following 9 times: jah(urlOne); and then
    1 time: jah(urlTwo); then it should start at the top again.
    There has to be a break in between, thats why i have the wait function
    there.
    Hope anybody can help me because i'm not seeing my mistake and can't
    think clear any more.
    You've not explained what's going wrong.

    Anwyay:
    function wait(msecs)
    {
    var start = new Date().getTime( );
    var cur = start
    while(cur - start < msecs)
    {
    cur = new Date().getTime( );
    }
    }
    NEVER EVER DO THAT. It will use up 100% of your CPU and probably will
    block your host (browser) completely until the timeout is
    finished. Possibly the host will break your script to prevent that.

    Use setTimeout() instead; something like:

    var count = 0;
    function nineTimes() {
    if (count++ < 9) {
    jah(urlOne);
    setTimeout(nine Times, 1000);
    }
    else {
    setTimeout(func tion() { jah(urlTwo) },1000);
    }
    }
    nineTimes();


    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

    Comment

    • ZT.Ph34rl3ss@gmail.com

      #3
      Re: Repeat with pause

      Thank you all 3 of you, i'm amazed by the answer and the speed the
      were provided in.
      Will post my code and the site when i'm done.

      Thanks again!

      Gr,

      Jeroen

      Comment

      Working...