Google gadget boolean preference doesn't seem to work
I am simply trying to read a user's boolean preference in a Google Gadget, but it seems that the preference is never getting saved at all, and I only ever get whatever the default_value is. I've broken this down into a very simple test case. Here is my test gadget spec:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Gadget to test bool">
</ModulePrefs>
<UserPref name="testpref" display_name="Test Boolean Preference" default_value="true" datatype="bool" />
<Content type="html">
<![CDATA[
&l开发者_如何转开发t;script type="text/javascript">
var prefs = new gadgets.Prefs();
alert(prefs.getBool('testpref'));
</script>
]]>
</Content>
</Module>
What I expect to see is an alert with true
or false
in it for whatever the user has chosen in the preferences dialog. However, the user's preferences are completely ignored, not saved, and even my default value isn't shown in the preferences. When I specify true for the default value, the preference checkbox remains unchecked.
What am I missing?
Edit: I am trying to get this working on a Google Apps Google Sites Start Page.
I tested your sample code in iGoogle and it seems to be working correctly. That is a box can be checked or unchecked and the alert is fired with the correct value.
As far as I know certain types of gadget containers do not allow user preferences - so the gadget that will work in iGoogle will not work correctly in standard Google Sites pages (apart from user customisable-type page).
Another common problem with code "not working" in iGoogle is caching of the gadget code. To force a gadget not to cache add "?nocache" to the gadget URL...
精彩评论