jQuery AJAX Refresh in an iFrame

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.

Nate Goes Lullabot

September 29 marked another big shift in my lifestyle. It concluded the my day of work at 220solutions/cvbTV, and marked the first day of full-time work at Lullabot. I'll now be doing Drupal development fulltime, along with occasional training sessions and consulting.

The 'bots flew me up to San Francisco this past week to meet most of the crew and sit in on the latest workshops. I couldn't ask for a better group of people to work with. Besides the people, we've also got some awesome projects in the pipe that I'm really excited about.

Free GPL Icons

I completed a sweet set of icons for use in any web or development project. The icons are licensed under the GNU General Public Lisence, and have been released on the Lullabot website.

You can download the complete set from Lullabot, complete with 'source' Photoshop files. If you're interested in contributing, or just developing some Photoshop skills, check out my article on creating small vector-based icons.

xkcd

A coworker pointed me to a comic from the site xkcd. Hilarious for the *nux inclined. I already bought a T-Shirt. You might also dig this comic (another for geeks) or this comic (laymen).

MTV UK goes Live!

MTV UK launched their new site August 1st, powered by Drupal. I played a significant role in the development of the site: theming, custom modules, client support, and of course enhancing the webform.module, which started the whole affair. Working with such a large, global company I expected that I would be dealing with humorless suits. Much to my surprise, our company contacts are super-cool. And since their Brits they say cool things like "Cheers" and "Righto". Awesome.

MTV is using the new powers granted by Drupal to determine programming for their new television channel "MTV Flux", where users contribute their own content. Based on website feedback popular content is then played on Flux.

 

Check out the press release from Lullabot for more information.

Pages