This is a short article about iGoogle gadgets. The Gadgets API is easy to use, but documentation is really fuzzy.
Gadgets are mini applications that use the IGoogle framework and can live inside other sites. In short, it's a page inside an
There are several steps to creating your first gadget:
- Sign up for the Sandbox. Note: the behavior of the application in Sandbox is different from that in the IGoogle home page (looks like they use different JS libraries).
- Add developer tools. These tools will protect your gadget from caching.
- Use the online editor or any other editor to create your gadget.
- Publish your gadget.
Using the code
The full gadget code is available here.
I decided to create a gadget which displays the hot deals from Expedia.com. After a few minutes in Google, I found the DataSource for my gadget - Expedia RSS Feed.
The gadget has two presentation parts:
- a form to configure the gadget;
- a list of entries from the feed;
title="Travel Deals on Expedia"
description="Hot Travel Deals from Expedia.com. Cheap flights
and hotels, cruises and top deals."
directory_title="IG Expedia Hot Deals"
In the code above, we are setting up all the required settings for a future gadget and including two modules at the end: "setprefs" and "dynamic-height". The first module allows us to programmatically save the user settings, the second one allows to adjust the height of the
IFrame (if content height was changed).
pgLoad function will be called and a page will finish the loading process. Actually, the IG framework will add the following line at the end of the body.
Note: looks like "
registerOnLoadHandler()" works only inside the Sandbox.
var m_UsrPref = new _IG_Prefs(__MODULE_ID__);
It's easy to read/write settings, but you must declare these settings first.
Now, we want to read the RSS feed:
var html = "";
if(obj && obj.Entry)
var n = obj.Entry.length;
for(var i=0; i<n; i++)
The framework will automatically refresh feed every 60 minutes or so.
Note: looks like "
gadgets.io.makeRequest()" works only inside the Sandbox. In general,
gadgets.io* functions work only in the dev environment, and only
_IG_* is really working.
This call will adjust the size of the
IFrame to fit the content height (again, don't try to use
adjustHeight). Now, we can publish our gadget and share it with friends.