xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] WebView does not open mailto: and tel: links on Android #8386

Open Mikilll94 opened 4 years ago

Mikilll94 commented 4 years ago

Description

On Android, WebView does not open links with mailto: or tel: href attribute

Steps to Reproduce

  1. Run the attached project
  2. Click on this email: salon@vintagerockhair.co.uk
  3. An error pops up:

image

Expected Behavior

When tapping an email link - mailbox should open When tapping a phone link - phone dialer should

Actual Behavior

Page with info "Webpage not available" opens.

Basic Information

Problem exists only on Android. On iOS and UWP everything works fine.

Screenshots

Reproduction Link

App1.zip

hartez commented 4 years ago

Original repro doesn't build, so here's another: _8386 Repro.zip

Mikilll94 commented 4 years ago

I will add also that if you change code in @hartez repro project in MainPage.xaml.cs to this:

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            var htmlSource = new HtmlWebViewSource();
            htmlSource.Html = @"<html><body><p>This is a WebView!</p>
            <div>
                <a href=""mailto:cfinley@fake.com"">Send an email</a>
                        </div>
                        <div>
                <a href=""tel:123456789"">Call me</a>
                        </div>
            </body></html>";
            TheWebView.Source = htmlSource;
        }
    }

you will see that tel: links on Android also do not work.

alallo commented 4 years ago

Is there any workarournd for this? the best I got so far is to reload the content of the WebView. In that way the error page will show and quickly be replaced by the original page

mphill commented 4 years ago

You can use the Navigating event. WebNavigatingEventArgs.Url will have the target, then you can do something like this:

            if (e.Url.StartsWith("http"))
            {
                Browser.OpenAsync(e.Url);
                e.Cancel = true;
            }