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

本文关键字:forms webview xamarin 浏览器 外部 链接 | 更新日期: 2023-09-27 18:07:10

我有一个webview,其中一些html内容显示与一些javascript和jquery和CSS。在这个html内容中,我有一些锚标记(…)与target="_blank"属性。当我点击这些链接,它在相同的网页视图打开,但不是这样做,我想把它打开到外部浏览器。

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

在webview上捕获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;
                }
            };