打开目标=“_blank”与 Xamarin.Forms WebView 的链接
我最近遇到了 target
属性设置为 _blank
的链接问题。点击它们没有任何效果。 WebView
不加载链接页面。
搜索周围我找到了这个解决方案: https://github.com/xamarin/Xamarin.Forms /issues/12917 正在设置 SetSupportMultipleWindows(false)
。更具体地说,建议是插入以下代码行:webView.Settings.SetSupportMultipleWindows(true);
。
尝试出现以下错误:错误 CS1061 'WebView' 不包含 'Settings' 的定义,并且找不到接受类型 'WebView' 的第一个参数的可访问扩展方法 'Settings' (您是否缺少使用指令或程序集引用?)
有没有办法克服该错误?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过多次尝试错误的方向后,我找到了对我有用的代码行。在
Custom Webview Renderer
中的OnElementChanged
方法的重写中,以下代码可以打开具有target=_blank
属性的链接:Control.Settings.SetSupportMultipleWindows(false);
SetSupportMultipleWindows;
应设置为false,而不是正如所建议的那样正确。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 theCustom Webview Renderer
this is the code that makes the opening of links withtarget=_blank
attribute possible:Control.Settings.SetSupportMultipleWindows(false);
SetSupportMultipleWindows;
should be set to false, not to true as it has been suggested.您可以使用以下代码在混合渲染器的OnElementChanged中添加对多个窗口的支持:
编辑:
You could add support for multiple windows in OnElementChanged of Hybrid renderer with code:
edit: