简体   繁体   中英

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?

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/");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM