Web Analytics Made Easy -
StatCounter setTimeout not working correctly - CodingForum

Announcement

Collapse
No announcement yet.

setTimeout not working correctly

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • setTimeout not working correctly

    Help please.

    I am trying to get a page to reload every two minutes using setTimeout but it seems to be ignoring the number of seconds entered.

    I have created a simple program which simply displays the date & time, but the time is being incremented by the second. You can see the program at :-

    http://home.iprimus.com.au/nomadiclifestyle/test.html

    The script I am using is :-

    <script type="text/javascript">
    ourDate = new Date();
    document.write('The last update was :- <BR>'
    + ourDate.toLocaleString() +
    '.');
    theUrl = 'test.html';
    location.replace(theUrl); setTimeout("location.replace()",1200000)
    </script>

    The 1200000 is being ignored. Can someone help please

  • #2
    you called a function which needed a parameter - location.replace(theUrl);, but you have not sent any paramater to it within setTimeout.

    Try:

    <script type="text/javascript">
    function bla(){

    ourDate = new Date();
    document.write('The last update was :- <BR>'
    + ourDate.toLocaleString() +
    '.');
    theUrl = 'test.html';
    location.replace(theUrl);
    setTimeout("bla()",1200000)
    }
    window.onload = bla;
    </script>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    Comment


    • #3
      ... and

      1. the setTimout() has to be palced inside the function you want to repeat

      2. you need an event to fire first time the function (onload, probably, as I guessed).
      KOR
      Offshore programming
      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      Comment


      • #4
        why not just do location.reload()?

        window.onload = function(){setTimeout("location.reload()", 120000)}

        or:

        <body onload="('location.reload()', 120000)">

        The zeroes in the delay you set exceeds by 1 making it 1.2M instead of 120K milliseconds.
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Thanks Guys

          Thanks Guys!!!

          It is working great.

          Thanks again.

          Comment

          Working...
          X