1

I have an index page with iframes, two of the iframes I want to re-load in sequence, iframe1 at 20 seconds, then iframe2 20 seconds later, then iframe1 again in 20 seconds, then iframe2 again in 20 seconds, forever.

I have tried sleep() in php, , and other javascript.

Why does php and javascript not support a simple script pause?

do ( '1' < '2' ) {

sleep(20);

echo script type="text/javascript

echo 'parent.featuredBottom.location = "modules/featured-bottom.php"';

echo /script>

sleep(20);

echo script type="text/javascript

echo 'parent.randomBottom.location = "modules/random-bottom.php"';

echo /script

}

sleep(); pauses everything..

1
  • 1
    while (TRUE) is a nicer than do ( '1' < '2' ) IMO. Commented Aug 16, 2011 at 3:11

1 Answer 1

1

JavaScript has a function called setTimeout(), which will wait for a specified number of milliseconds and then execute some code.

In the onload (or document ready, whatever) of each iframe use setTimeout() to control the reload of the other iframe.

// within the iframe1 content:
<body onload="iFrame1Loaded();">
...


function iFrame1Loaded() {
  setTimeout(function() {
    // put code here to tell iFrame2 to reload,
    // parent.frames["iframe2"].something.something...
  }, 20000);
}

And then basically the same thing in your iFrame2, with the 1s and 2s reversed...

More info about setTimeout() is available at the MDN website.

Note: do not attempt to implement your own sleep() function in JavaScript, because it will lock up the browser - the user won't be able to scroll, it won't repaint, etc., until the sleep is over.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.