Search code examples
silverlightwindows-desktop-gadgets

Silverlight based gadget to open link in a browser?


I have written a sidebar gadget which displays a series of links using silverlight. I can host the silverlight in a web site and when I click on the links they open in a new tab. When I package it up as a gadget however the links appear in the gadget, and they can be clicked on, but they do not open a browser window to display the link.

What do I need to do to get this to work?


Solution

  • It's best to launch external links from gadgets using your preferred shell execute method; doing so will launch them in the default browser. When developing gadgets, all my links have an onclick handler which points to the following method:

    function launchLink() {
        if (this.href.slice(0,7) == "http://") {
            System.Shell.execute(this.href);
            return false;
        }
    }
    

    Theoretically, you could modify this slightly and invoke it from your Silverlight code using the HTML bridge.

    JS code

    function launchLink(href) {
        System.Shell.execute(href);
    }
    

    Silverlight

    // HtmlPage requires using System.Windows.Browser
    HtmlPage.Window.Invoke("launchLink", "http://some.com/");