我最近遇到了將target屬性設定為_blank. 點擊它們沒有任何效果。WebView不加載鏈接的頁面。
環顧四周,我找到了這個解決方案:https://github.com/xamarin/Xamarin.Forms/issues/12917這是設定SetSupportMultipleWindows(false)。更具體地說,建議是插入以下代碼行:webView.Settings.SetSupportMultipleWindows(true);.
嘗試我收到以下錯誤: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?)
有沒有辦法克服錯誤?
uj5u.com熱心網友回復:
您可以使用代碼在混合渲染器的OnElementChanged中添加對多個視窗的支持:
Control.Settings.SetSupportMultipleWindows(true);
編輯:
public class MyWebViewRenderer : WebViewRenderer
{
public MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if(Control!=null)
{
Control.Settings.SetSupportMultipleWindows(true);
Control.Settings.JavaScriptEnabled = true;
Control.SetWebChromeClient(new MyWebChromeClient());
}
}
}
public class MyWebChromeClient: WebChromeClient
{
public override bool OnCreateWindow(Android.Webkit.WebView view, bool isDialog, bool isUserGesture, Message resultMsg)
{
if(!isDialog)
{
return true;
}
return base.OnCreateWindow(view, isDialog, isUserGesture, resultMsg);
}
}
}
uj5u.com熱心網友回復:
經過多次嘗試錯誤的方向后,我找到了對我有用的代碼行。在重寫OnElementChanged方法中,Custom Webview Renderer這是使打開帶有target=_blank屬性的鏈接成為可能的代碼:
Control.Settings.SetSupportMultipleWindows(false);
SetSupportMultipleWindows;應該設定為false,而不是建議的true。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/446870.html
標籤:xamarin xamarin.forms 网页浏览 android-webview
上一篇:CS0115'HybridWebViewRenderer.OnCreateWindow(WebView,bool,bool,Message)':找不到合適的方法來覆寫-Xamari
