如何从浏览器外的 Silverlight 打开弹出窗口?

发布于 2024-09-05 09:43:05 字数 770 浏览 7 评论 0原文

我需要从 Silverlight 浏览器外应用程序打开弹出窗口。

我在 Index.html 中添加了参数 ,但从代码后面执行此操作:

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

仍然返回错误:

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

我已阅读有关 < a href="https://stackoverflow.com/questions/2677536/silverlight-4-oob-application-access-html-dom-of-the-page-in-webbrowser-control/2708194#2708194">这个帖子,这是否意味着我无法从OOB打开弹出窗口?为什么我需要这样做,因为实际上我已经通过 ChildWindow 中的 WebBrowser 控件在 OOB Silverlight 中显示了 HTML 页面,但是当我单击 HTML 页面中的锚点时,链接到_blank页面,它跳转到我的默认浏览器。它不满足要求,除了第一次也在默认浏览器中启动 HTML 索引页面,由 OOB Silverlight 中的按钮控件触发。这可能吗?

请指教,谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

熟人话多 2024-09-12 09:43:05

不确定这是否是您想要的,但尝试一下...

在 OOB 应用程序中,您可以使用以下解决方法:

创建一个派生的超链接按钮,如下所示:

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

使用该按钮进行导航:

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

参见 forums.silverlight.net

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

夜司空 2024-09-12 09:43:05

不,这是不可能的。在 OOB 应用程序中,与 HTML 桥的任何交互都被禁用。

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

明月松间行 2024-09-12 09:43:05

我今天遇到了这个问题,这就是我在 SilverLight 5 中解决它的方法:使用以下代码创建一个新类

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

:使用它:

private void hlViewMarketplace_Click(object sender, RoutedEventArgs e)
        {
            Uri destination = new Uri("http:///www.google.com/" + ((HyperlinkButton)sender).CommandParameter);
            WebBrowserBridge.OpenURL(destination, "_blank");
        }

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");
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文