question

UserSense-9370 avatar image
0 Votes"
UserSense-9370 asked LeonLu-MSFT commented

Xamarin.Forms Webview window.open or _blank

I'm using Xamarin.Forms' Webview component, which does the trick for me most of the time, but there are limitations. I'm unable to detect the following navigation events.

  • window.open()

  • Links with a _blank target

Basically all links or locations that would normally open a new tab or window.

  • Is there an easy way to detect these events? Both navigating and navigated don't get fired.

  • Can I solve this with a Custom Webview Renderer? How?

I eventually want to capture the specfic url and load it in the current webview, or add an additional webview as tab in my app.


dotnet-xamarin
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Which platform do you want to achieve this function? For android, we can create a custom renderer, then create a custom WebViewClient with webView.SetWebViewClient(new MywebviewClient());, we can override the OnPageStarted and OnPageFinished method in the MywebviewClient. when you open a new tab or window. these methods will be executed.

internal class MywebviewClient : WebViewClient
    {
        public override void OnPageStarted(WebView view, string url, Bitmap favicon)
        {
            base.OnPageStarted(view, url, favicon);
        }
        public override void OnPageFinished(WebView view, string url)
        {
            base.OnPageFinished(view, url);
        }

        
    }


https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview

0 Votes 0 ·

0 Answers