Setting Your Gadget Title Programmatically
In certain circumstances, you may need to programmatically reset the title of your gadget—for example, if you are attempting to personalize all elements of the application to the current user’s profile. In this case, you may want to capture profile information about the user, such as his name, and reset the gadget title to something like “Erik’s Task List.”
To integrate this feature, take these steps:
Within the
ModulePrefsnode of the gadget spec file, add aRequireelement to enable thesettitleJavaScript library.Include:
<Require feature="settitle"/>
When you wish to reset the gadget title, call the
setTitle()method of thegadgets.windowobject.Method call:
gadgets.window.setTitle();
<Module>
<ModulePrefs>
<Require feature="settitle" />
</ModulePrefs>
<Content view="canvas"><![CDATA[
<form name="titleForm">
Input new gadget title<br />
<input type="text" name="newTitle"><br />
<button onclick="setTitle();">Set New Title</button>
</form>
<script type="text/javascript">
function setTitle(){
//capture user title input
var newTitle = form.newTitle.value;
//set the gadget title
gadgets.window.setTitle(newTitle);
}
</script>
]]></Content>
</Module>Note
The full code for this sample is available at https://github.com/jcleblanc/programming-social-applications/blob/master/chapter_4/setting_gadget_title.xml.
In the preceding example, we include the Require statement to initialize the settitle library. Within the Content section, we set up a simple ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access