My favorites | English | Sign in

How to Add O3D to a Gadget

Overview

This document outlines how to use O3D inside an iGoogle or OpenSocial gadget. This process is very similar to creating a standalone page, except for a few restrictions imposed on the gadgets. iGoogle itself provides a very brief guide on how to migrate a standalone page.

Converting an O3D Application into a Gadget

Gadgets are essentially the same as pages, except that you only have control over a small part of the page—you cannot change the <head> section, and a lot of other things may be put in the body for you.

  1. Since both OpenSocial and iGoogle will add a lot of JavaScript to the generated page for you, you cannot overwrite window.onload. Instead, you must use the provided API for registering such events. For instance, a call like this:
    window.onload = myInitFunction;

    should become something like this on both iGoogle v2 and OpenSocial:

    gadgets.util.registerOnLoadHandler(myInitFunction);

    or, if using the legacy iGoogle API:

    _IG_RegisterOnloadHandler(myInitFunction);
  2. If you wish to set the title of the gadget, you cannot access <head><title>. Instead, add the title to your module preferences, like this:
    <ModulePrefs 
       title="My cool O3D app" 
       title_url="http://www.mydomain.com/" 
       height="200" 
       author="Jane Smith" 
       author_email="name@mydomain.com"
    />  

    or set it dynamically with:

    gadgets.window.setTitle("My cool O3D app");
  3. If you are using utility libraries (e.g., o3djs/base.js), host the utilities on a server so that they are available via http:
    <script type="text/javascript" src="http://www.mydomain.com/o3djs/base.js</script>

    If listing your utility libraries using o3djs.require, also specify the base path of the 'o3djs' utilities directory location. For example:

    o3djs.basePath=http://www.mydomain.com/;
    o3djs.require('o3djs.util');
    o3djs.require('o3djs.event');

Testing the Gadget

  1. To test your gadget, save the gadget's XML file on a publicly accessible web server and then use that URL to embed it in a page that supports gadgets. For example, in iGoogle navigate to your iGoogle page and click "Add Stuff." The page will display an "Add feed or gadget" link. Enter the URL of your gadget's XML file.
  2. By default, gadget XML specs are cached by the gadgets server. When developing gadgets and making frequent changes to the XML spec, you may want to disable gadget caching, so that changes are immediately reflected every time the page is refreshed.
  3. To disable caching, append the ?nocache suffix to the URL of your gadget XML specification. For example: http://www.mydomain.com/mygadget.xml?nocache.