RMR
RMR

Reputation: 629

How to open anchor tag links in external browser instead of open in same webview in xamarin.forms

I have one webview where some html content are display with some javascript and jquery and CSS. In this html content I have some anchor tag (...) with target="_blank" attribute. when I click on these links its open in same webview page but instead of doing this I want to open it into external browser. How is this possible in xamarin forms.

Upvotes: 0

Views: 820

Answers (1)

M. Wiśnicki
M. Wiśnicki

Reputation: 6203

Catch Navigating Event on your webview and call 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;
                }
            };

Upvotes: 3

Related Questions