When opening a link to a website from my WebView both with Android and iOS I'm able to do it with the default browser of the phone. However, when going back to the app, with Android I see the expected and desired behavior of seeing the original WebView page, instead on iOS I see the opened website inside the application. Here the GitHub link to reproduce the behavior: https://github.com/irdalan/WebViewTestApp
Behavior for Android: From left to right:
- AndroidApp before clicking on the link 2. Navigating to link with default browser on Android 3. AndroidApp after going back from browser to App.
Behavior for iOS: From left to right:
- IphoneApp before clicking on the link 5. Navigating to link with default browser on iOS 6. IphoneApp after going back from browser to App.
EDIT: Code behind of webview page
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace WebViewTestApp
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
HtmlWebViewSource localhtml = new HtmlWebViewSource();
string text = "<html><body><h1>Xamarin.Forms</h1><p>Welcome to WebView.<a href= \"https://en.wikipedia.org/wiki/Xamarin\">Xamarin</a></p></body></html>";
localhtml.Html = text.Replace(@"\", string.Empty);
_webview.Source = localhtml;
_webview.Navigating += async (s, e) =>
{
if (e.Url.StartsWith("http"))
{
try
{
var uri = new Uri(e.Url);
await Launcher.OpenAsync(uri);
}
catch (Exception ex)
{
}
finally
{
e.Cancel = true;
}
}
};
}
}
}





