tags:

views:

20

answers:

2

I need one of my frames to change its contents whenever the server decides it's time. Is that possible? Can RSS be used for that? Does it demand too much in terms of network and processing?

A: 

This probably isn't the most resource-efficient way to do it, but you can use the setTimeout function recursively. Below is an example.

<html>
  <head>
    <script type="text/javascript">
      var t;
      function setTimeout_recursive(statement,interval){
        t = setTimeout(statement,interval);
      }
    </script>
  </head>
  <body onload="setTimeout_recursive('document.getElementById(\'blah\').src=\'page.php\';',5000);">
    <iframe id="blah"></iframe>
  </body>
</html>

The file page.php is my hypothetical script to load new content. You can replace this with whatever file you're using for this purpose.

The interval variable is the delay in milliseconds between the time of the function call and when the code in the string statement is executed. Normally recursion uses an exit function in order to prevent infinite loops; in this case, however, since there's a sizable delay, it shouldn't be resource-intensive enough to lock up the browser.

Again, this is probably a VERY BAD way of doing this for multiple reasons, but it was the first thing that came to mind. It's much better to use AJAX in most cases where you want dynamic content loading. (The only situation I can think of where it's not is for file uploads where you want the user to stay on the same page instead of submitting a form and being redirected.)

Cheers, and good luck.

A: 

You can achieve this using Javascript.

I'd use jQuery, with a server-side script returning json rather than XML/RSS. Polling is a common strategy, along with non-terminating responses.

Don't use frames, let your jQuery put the content in a DIV.

Emyr