3

I need to open window pop-up from Silverlight Out-of-Browser application.

I've added parameter <param name="enablehtmlaccess" value="true" /> in Index.html, but executing this from code behind:

HtmlPage.Window.Navigate(new Uri(myUrl), "_blank", myFeatures);

still returns error:

Silverlight OOB Error: The DOM/scripting bridge is disabled.

I've read about this post, does it mean that I can't open pop-up from OOB? Why I need to do this, because actually I've shown the HTML page in OOB Silverlight by WebBrowser control within ChildWindow but when I click an anchor in HTML page, which linked to _blank page, it jumps to my default browser. It doesn't meet the requirement, except launch that HTML index page also in default browser at the first time, triggered from button control in OOB Silverlight. Is that possible?

Please advice, thanks.

Community
  • 1
  • 1
Jeaf Gilbert
  • 11,495
  • 19
  • 78
  • 105

3 Answers3

4

not sure if this is what you are after, but try this...

In an OOB app, you can use the following work around:

Create a derived hyperlink button like this:

public class MyHyperlinkButton : HyperlinkButton 
{ 
        public void ClickMe() 
        { 
                base.OnClick(); 
        } 
} 

Use that for navigation:

private void NavigateToUri(Uri url) 
{ 
        if (App.Current.IsRunningOutOfBrowser) 
        { 
                MyHyperlinkButton button = new MyHyperlinkButton(); 
                button.NavigateUri = url; 
                button.TargetName = "_blank"; 
                button.ClickMe(); 
        } 
        else 
        { 
                System.Windows.Browser.HtmlPage.Window.Navigate(url, "_blank"); 
        } 
}

see forums.silverlight.net

tkerwood
  • 1,875
  • 16
  • 26
3

I came across this problem today and this is how I solved it in SilverLight 5: Create a new class with the following code:

/// <summary>
/// Opens a new browser window to the specified URL with the specified target
/// For use while running both in or out-of-browser
/// </summary>
public class WebBrowserBridge
{
    private class HyperlinkButtonWrapper : HyperlinkButton
    {
        public void OpenURL(String navigateUri, String target = "_blank")
        {
            OpenURL(new Uri(navigateUri, UriKind.Absolute), target);
        }

        public void OpenURL(Uri navigateUri, String target = "_blank")
        {
            base.NavigateUri = navigateUri;
            TargetName = target;
            base.OnClick();
        }
    }

    public static void OpenURL(String navigateUri, String target = "_blank")
    {
        HyperlinkButtonWrapper hlbw = new HyperlinkButtonWrapper();
        hlbw.OpenURL(navigateUri, target);
    }

    public static void OpenURL(Uri navigateUri, String target = "_blank")
    {
        HyperlinkButtonWrapper hlbw = new HyperlinkButtonWrapper();
        hlbw.OpenURL(navigateUri, target);
    }
} 

Here's how to both implement & use it:

private void hlViewMarketplace_Click(object sender, RoutedEventArgs e)
        {
            Uri destination = new Uri("http:///www.google.com/" + ((HyperlinkButton)sender).CommandParameter);
            WebBrowserBridge.OpenURL(destination, "_blank");
        }
Agilis
  • 328
  • 2
  • 11
  • I don't see how this solves the problem in an OOB scenario. Can you describe how it applies to opening browser popups in OOB? – RobSiklos Jan 18 '13 at 16:52
  • @RobSiklos Okay I must have misunderstood the question. My issue today was when I tried to open up a webpage from my SilverLight OOB application, I received the dreaded 'The DOM/scripting bridge is disabled.' So I used what I posted above to get around this issue. Now when I click on a button, I'm able to open the URL in a browser window from my app's code-behind. – Agilis Jan 18 '13 at 16:57
3

No this is not possible. In an OOB application, any interaction with the HTML bridge is disabled.

Ray Booysen
  • 28,894
  • 13
  • 84
  • 111