2

I have a WebView in my .Maui app that displays a forum for users to use with my app. But I've noticed that if anyone posts a link that requires the WebView to open the link in a new window, nothing happens. My initial thought was to capture the URL of the link the user selects using the Navigating event, but it is never triggered for these links, only for the ones that open their destination within the WebView itself. Has anyone here faced this dilemma and what did you do to solve it?

Hwew's the code I've tried so far, which fired fine for links that don't need to open in a new window, but ignores the links that do:

public BlenderPage()
{
    InitializeComponent();
    BlenderWebview.Navigating += BlenderWebview_Navigating;
}

private void BlenderWebview_Navigating(object sender, WebNavigatingEventArgs e)
{
    Console.WriteLine(e.Url.ToString());
}

Also, this issue is happening with the .NET Maui android app version

Jason O
  • 753
  • 9
  • 28

1 Answers1

2

Here is Android developer documentation for How to Build web apps in WebView. You may take a look if you want.

Also found a similar issue on StackOverflow: MAUI Webview target="_blank" href redirects not working on android. In this case, Liyun Zhang's answer mentioned that you could try add android:usesCleartextTraffic permission. Andrew answer created a Webview handler using Platform code to modify settings. You may try their answers. For more info about Handlers, you could refer to Maui Handlers and WebViewHandler.

Hope it works for you.

Liqun Shen-MSFT
  • 3,490
  • 2
  • 3
  • 11