首页 文章

如何在外部浏览器中打开锚标记链接,而不是在xamarin.forms中的同一webview中打开

提问于
浏览
0

我有一个webview,其中一些HTML内容显示有一些javascript和jquery和CSS . 在这个html内容中,我有一些 anchor tag (...) with target="_blank" 属性 . 当我点击这些链接时,它在同一个webview页面中打开,但我没有这样做,而是想把它打开到外部浏览器中 . 这在xamarin形式中是如何实现的 .

1 回答

  • 3

    在您的网页浏览中 grab Navigating Event 并致电 Device.Open(your uri)

    webview.Navigating += (s, e) =>
                {
                    if (e.Url.StartsWith("http"))
                    {
                        try
                        {
                            var uri = new Uri(e.Url);
                            Device.OpenUri(uri);
                        }
                        catch (Exception)
                        {
                        }
    
                        e.Cancel = true;
                    }
                };
    

相关问题