A more sophisticated solution would use ajax-y techniques.
Tim,
I have tried the first solution you suggested me, with iframe. I have tried many different javascripts to reload the iframe but I couldn't make it works. This one bellow reloads the whole page instead of the iframe only. I've put and activate this script from the iframe.
<script language="JavaScript">
<!--
var sURL = unescape(window.frames['my_iframe'].location.pathname);
function doLoad()
{
setTimeout( "refresh()", 5*1000 );
}
function refresh()
{
window.location.href = sURL;
}
//-->
</script>
Can you suggest me what is wrong here?
Thanks
If the window is the main window (course page), do I have to access the block object before trying to reach my frame included in block? Where should I put JavaScript code to access this iframe?
The iframe source being the content of your iframe, not the page/block containing the iframe itself.
When the iframe source file is loaded, the meta refresh will refresh that at the interval specified in the meta content (in the case of my previous example, every 5 seconds). But it should only refresh the content of the iframe, not the page containing it.
Argh, hard to explain!
That was the first thing I have tried. I have tried it again now, but it refresh the whole page again. I have tried to put
echo '<META HTTP-EQUIV="Refresh" content="5" url="includedContent.php">';
at the top of the included page, as well as in the block page (before block class and in the function get_content), and nothing again.
This sounds as a good solution, but it doesn't works for me, or I do it on the wrong way.
Your block code might look like this....
<?php
class block_testblock extends block_base {
function init() {
$this->title = 'Test Block';
$this->version = 2007101509;
}
function get_content() {
global $CFG;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->text = '<iframe src ="block_content.php"></iframe>';
$this->content->footer = '';
return $this->content;
}
}
?>
And the "block_content.php" would contain something like this....
<?php
echo '<head><meta http-equiv="refresh" content="5" /></head>';
// After here do your magic //
?>
My apologies if it doesnt actually work.
Hmm, if I get some time in a bit I'll try it out.
In the html/php file that is the source for your iframe, put something like this at the top...
<head><meta http-equiv="refresh" content="5"/></head>
The above will refresh the page every 5 seconds, but should only refresh the page that is viewed through the iframe, not the page the iframe resides on. Ive used this in the past, it might work for you.
One thing though, its good practice to allow the user to change the refresh time, or to turn off the automatic refresh entirely.
I will admit, this technique (iframe/meta refresh) is not as nice as whatever you could do with some ajax, but it is quite simple in comparison.