Tinkering around with a jQuery enabled Drupal module today, I was trying to make an iFrame that continuously updated. I tried the typical meta-tags and window.location.refresh() javascript but I wasn't satisfied with constant progress bar on the page. An AJAX (or AHAH really) request was needed to make this work smoothly.
The trick was combining some standard javascript selectors with the jQuery $ function. Here's my iframe:
And this is what was needed to select the top-level HTML tag within my iframe. Note that the 'script-console' used below is the name attribute of the iframe, not the id.
$('html', window.frames['script-console'].document);
So now to actually add the jQuery request and modify the iFrame:
function refreshConsole() {
$('body', window.frames['script-console'].document).loadIfModified("mytextfile.txt");
setTimeout("refreshConsole()", 1000);
}
$(document).ready(function() {
refreshConsole();
});
This code (placed the HEAD tag of the page), defines a refreshConsole function. Every second (1000 milliseconds), refreshConsole calls itself again. Every call, jQuery check the file "mytextfile.txt" for changes. If it's been updated, it retrieves the text and replaces the contents of the iFrame's BODY tag.