Search code examples
xamarinxamarin.formswebviewandroid-webview

Opening target="_blank" links with Xamarin.Forms WebView


I have recently encountered an issue with links having the target attribute set to _blank. Tapping on them has no effect. The WebView does not load the linked page.

Searching around I found this solution: https://github.com/xamarin/Xamarin.Forms/issues/12917 which is setting SetSupportMultipleWindows(false). More specifically the suggestion is to insert the following line of code: webView.Settings.SetSupportMultipleWindows(true);.

Trying that I get the following error: Error CS1061 'WebView' does not contain a definition for 'Settings' and no accessible extension method 'Settings' accepting a first argument of type 'WebView' could be found (are you missing a using directive or an assembly reference?)

Is there a way to overcome the error?


Solution

  • After many tries towards the wrong direction I found the line of code that worked for me. In the override of the OnElementChanged method in the Custom Webview Renderer this is the code that makes the opening of links with target=_blank attribute possible:

    Control.Settings.SetSupportMultipleWindows(false);

    SetSupportMultipleWindows; should be set to false, not to true as it has been suggested.