Need help on using javascript to reload page!

Discussion in 'JavaScript' started by dreteh, Jan 28, 2010.

  1. #1
    Hello,

    I have a piece of js to refresh a page by a timer. Like following:

    ------------------------------------------------------------
    <script>
    function starttimer()
    {
    if(time's up)
    reload();
    else
    keep counting...
    }
    </script>
    <body onload="starttimer()">
    --------------------------------------------------------------
    The problem with the above script is the timer won't start unless the page is done loading.
    Is there any way I can get around this so that the page can be reloaded on a fixed time interval regardless if the page is still being load or not.

    Thanks in advance.
     
    dreteh, Jan 28, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Hi dreteh,

    Try this:
    
    <script>
    function starttimer()
    {
    if(time's up)
    reload();
    else
    keep counting...
    }
    </script>
    <body>
    <script>starttimer();</script>
    .................................................
    
    Code (markup):
    Regards,
    Nick
    :)
     
    koko5, Jan 28, 2010 IP
  3. fundoobuddy

    fundoobuddy Peon

    Messages:
    274
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <script type="text/javascript">
    setTimeout("document.location = location.href",HERE_TIME_IN_MILLISECOND);
    </script>
    
    Code (markup):
     
    fundoobuddy, Jan 28, 2010 IP
  4. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #4
    Thanks for the replies. But calling the function after body tag doesn't work. I am testing with Google chrome.
     
    dreteh, Jan 29, 2010 IP
  5. fundoobuddy

    fundoobuddy Peon

    Messages:
    274
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Works for Me

    
    <html>
    <head>
    <title>Reload Me</title>
    </head>
    <body>
    Some Text <br>
    <script type="text/javascript">
    setTimeout("document.location = location.href",1000);
    </script>
    
    Some Another Text <br>
    </body>
    </html>
    
    Code (markup):
     
    fundoobuddy, Jan 29, 2010 IP
  6. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #6
    Thank you guys.
    I solved the problem by calling $(document).ready(function() { } from jquery.
     
    dreteh, Jan 29, 2010 IP