0

I'm developing a simple gadget for Windows 7 as a learning exercise. I read in this article (under the subtopic Gadgets and Script) that to initialize the gadget, you should use document.onreadystatechange instead of events such as onLOad. I've seen it in the example project code I've looked through as well. This is what I came up with for my project.

document.onreadystatechange = function()
{
    if(document.readyState == "complete")
    {
        System.Gadget.settingsUI = "settings.html";  //this line enables the settings UI
        System.Gadget.onSettingsClosed = settingsClosed;
    }
}

However when I use this snippet in my work, it doesn't work. The Options button in the gadget doesn't show up. If I use onLoad, it works. I have installed 2 gadgets. Each of them use these 2 methods. One use onLoad and the other use document.onreadystatechange. And both of them works!

Now I'm confused why it doesn't work with my gadget. Is there any important part I'm overlooking?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Isuru
  • 30,617
  • 60
  • 187
  • 303

1 Answers1

0

try something along these lines, move your onsettingsclosed to a different event and call the function with it

document.onreadystatechange = function()
{    
    if(document.readyState=="complete")
    {
        var searchTags = System.Gadget.Settings.read("searchTags");
        if(searchTags != "")
        {
            searchBox.value = searchTags;
        }       
    }        
}

System.Gadget.onSettingsClosing = function(event)
{
    if (event.closeAction == event.Action.commit) 
    {
        var searchTags = searchBox.value;
        if(searchTags != "")
        {
            System.Gadget.Settings.write("searchTags", searchTags);
        }
        event.cancel = false;
    }
}
Brad Fox
  • 685
  • 6
  • 19
  • I have my script for settings just like that. The problem is the Options button which brings up the Settings UI doesn't show up the gadget at all. This line `System.Gadget.settingsUI = "settings.html";` should execute but as of now, it doesn't go _into_ that function. – Isuru Apr 09 '12 at 15:07
  • 1
    Do your other programs use this as well? i know you said the one gadget does use it, but what else sets that one aside from the one that wont work? if not what version of the Sidebar.Exe are you running? you will need version 1.00 or later, if this is not the case i will research further for you – Brad Fox Apr 09 '12 at 15:14
  • 1
    Also, is your HTML pages formatted correctly? i trust it is, just want to verify – Brad Fox Apr 09 '12 at 15:22
  • I've missed [this snippet](http://i.imgur.com/wTy1K.png) in my html page. In the sample project, its in the head section of the html page. When I put the same snippet in my code, the Options button showed up. Although I can't seem to think of the connection between those two. `GetFlair()` is a separate function. Thank you for taking time to look into my problem btw. – Isuru Apr 09 '12 at 16:39