Running Windows Sidebar Gadgets Directly in IE7

October 29th 2006 Sidebar Gadgets JavaScript Windows

Since gadgets are HTML applications and the Windows Sidebar uses Internet Explorer 7 to render them, I prefer running their code directly in IE7 during development. It makes debugging easier and allows me to develop them in Windows XP on my primary development machine with all the tools properly setup.

While this works great in early development stages, it becomes a problem later on when you start using the Windows Sidebar object model (to implement settings, visibility changes handlers etc.). This specific code understandably can only be debugged while running in Windows Sidebar but the unfortunate side effect is that the calls to objects which don't exist in IE7 break the scripts and effectively prevent running the would-be gadget in IE7 even without this functionality.

The following function can help you keep the gadget running directly in IE7 even after the gadget specific functionalities are already implemented:

function isGadget()  
{  
    try  
    {  
        var dummy = System;  
        return true;  
    }  
    catch (err)  
    {  
        return false;  
    }  
}

Just check if the application is running in Windows Sidebar at gadget startup and make sure to use the object model only when this is true. You can also add alternative initialization for running directly in IE7 to provide default values for settings and any other gadget specific variables. By doing this you can still test new features directly in IE7 if they are not gadget specific.

Get notified when a new blog post is published (usually every Friday):

If you're looking for online one-on-one mentorship on a related topic, you can find me on Codementor.
If you need a team of experienced software engineers to help you with a project, contact us at Razum.
Copyright
Creative Commons License