SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    0 Post(s)
    0 Thread(s)

    setTimeout() reloads instantly

    Hello there,

    I am having some problem with JavaScript's setTimeout() function.

    The result I want to achieve is this:
    Master page reloads the slave page every few seconds and the slave page redirects to the master page each time it's loaded. I know it's hard to comprehend why it's needed, but it is.

    The problem I'm having is this:
    The master page doesn't wait the given seconds to reload the slave page, but reloads it instantly. And the slave page does as it should and redirects to the master loop which by itself makes an endless loop of instantaneous redirections.

    Master page javascript ($sid variable exists and is recognized):
    <script type="text/javascript">
    location.href = '?m=history&sid=$sid&a=refresh';
    function timedRefresh(timeoutPeriod) {
    Here, the function timedRefresh() is called on the master page html like so:
    <body onload="timedRefresh(5000)">
    As I understand, it should wait 5 seconds, load the slave page, which by itself redirects to the master page and the wait begins again. For some reason, it doesn't work like that.

    The slave page works fine, you don't have to worry about that.

    I would greatly appreciate any help.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    0 Post(s)
    0 Thread(s)
    When you assign a value to location.href, the browser immediately obeys and loads it.

Tags for this Thread


Posting Permissions

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