location.reload(true) kills the System object?

I stuck a reload button in my gadget so I could easily refresh it to see the effects of changing something in the code. The onclick handler for the button is onclick="window.location.reload(true)".

This does in fact reload the HTML and JS. But it seems to also kill the System object hierarchy. The code "Display.innerText = System.Gadget.name;" works the first time the gadget is added to the sidebar. Then I click my reload button and I get an error trying to access the System object. If I wrap the call in a try/catch and look at the error, it says "'System' is undefined". If I then close the gadget and re-add it to the sidebar, the System object comes back.

I'm running the final version of Vista Ultimate in a Virtual PC instance on XP, so conceivably that's confusing something. But Vista seems to otherwise be pretty stable in VPC.

Has anyone seen this behavior How do you reload your gadgets

Thanks.



Answer this question

location.reload(true) kills the System object?

  • George Waters

    Virtual PC shouldn't make any difference.

    I have certainly seen the System object disappear during the beta and even did a bugrep on it, but was never able to pin down what actually caused it and produce a repro gadget.

    It's probably a pain, but recode it to update the elements instead of relying on a reload if you can.

    I'll have a play to see if I can reproduce this behaviour.


    EDIT: You're right, System does disappear after a reload - well spotted!  Definately a bug in Sidebar. You can repro it with the following gadget.html

    <HTML>
    <BODY style="width:100px; height:100px"
            onclick=window.location.reload(true);">
    <script language="javascript">
        try{
            document.body.innerText=System.Gadget.name;
        } catch(err) {document.body.innerText=err}
    </script>
    </BODY>
    </HTML>

  • Kamii47

    Jonathan Abbott wrote:
    It's probably a pain, but recode it to update the elements instead of relying on a reload if you can.

    The reload isn't for functionality in the gadget. It would only be used during development, to test changes as I make them.

    So is removing and re-adding the gadget really the only way to force it to display changes to its code That's so wildly inconvenient that it's hard to believe someone wouldn't have fixed it a long time ago. How do people usually develop these things


  • SPWilkinson

    The best way is to Exit Sidebar (right click on the tray icon) and then reload from the shortcut.

  • Ondra Br.

    Jonathan Abbott wrote:
    The best way is to Exit Sidebar (right click on the tray icon) and then reload from the shortcut.

    That's what I was afraid you'd say. :| Maybe there's a way to programmaticaly close the sidebar so you could create a script to close and then reopen it I know running "sidebar" in the Run dialog opens the sidebar. Or could the gadget remove itself and then execute a delayed script to re-add itself All seems a bit awkward.


  • cplusplus1

    taskkill -im sidebar.exe -f
    start /D "%ProgramFiles%\Windows Sidebar" sidebar.exe

  • Phil D.

    Here's another tip.

    Copy the above code and paste it into a text file called c:\restart_sidebar.bat

    In your Visual Studio project, go to Project properties and add this as a pre-build command step. Then from within Visual Studio, ctrl-shift-B will restart your Sidebar.


  • Vivek S

    You probably want to clear the temp directory as well, as Sidebar creates lots of temporary images in there:

    taskkill -im sidebar.exe -f
    del /q "%USERPROFILE%\appdata\local\temp\*.*"
    start /D "%ProgramFiles%\Windows Sidebar" sidebar.exe

  • location.reload(true) kills the System object?