Google Gadget Unique Identifier

How do I get a unique gadget id from a gadget added to iGoogle using Javascript?

+3
source share
2 answers

If you are trying to access the gadget id from JavaScript in the gadget itself, you can use __MODULE_ID__. This is automatically replaced by the iGoogle server with the actual module ID and is used in a number of standard libraries as a general constructor parameter (see the Gadgets API Reference ).

If you are using the new gadget API (part of the OpenSocial specification and is currently only available on iGoogle in iGoogle Sandbox), then you have another option:gadgets.Prefs.getModuleId()

+4
source

100%, , , URL- Google Gadgets : http://hosting.gmodules.com/ig/gadgets/file/unique_id/name.xml..., , Google JavaScript, <a> -tag onclick, amonst others URL. , , <a> -tags ( delbox) onclick, . , Google.

- ( ):

/**
 * Grabs the id of a Google Gadget from an iGoogle page.
 *
 * @param name the name of the targeted Google Gadget. If omitted the first
 *             Gadget is used
 * @return the id of the targeted Google Gadget or null if it could not be found
 */
function grab_id (name) {
    var links = document.getElementsByClass("delbox");
    var url = "http://hosting.gmodules.com/ig/gadgets/file/";
    var id_length = 21;
    var regex = url + "[\d]{" id_length} + "}/" + name;
    for (var i = 0; i < links.length; i++) {
        var match = links[i].getAttribute("onclick").match(regex);
        if (match) {
            return match.substring(url.length+1, url.length+1+id_length);
        }

    }
    return null;
}
+2

All Articles