WKWebView和window.open [英] WKWebView and window.open
问题描述
似乎网站上的许多链接在其onclick处理程序中使用window.open,但是WKWebView似乎完全忽略了window.open.
It appears that a lot of links on websites use window.open in their onclick handlers but WKWebView seems to completely ignore window.open.
是否有解决方法?
我尝试将javaScriptCanOpenWindowsAutomatically首选项设置为true,但这似乎无济于事
I tried setting javaScriptCanOpenWindowsAutomatically preference to true but that didn't seem to help
推荐答案
当Web应用程序在JavaScript中调用window.open()
时,WKWebView
将在其UIDelegate
上调用
- webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:
方法.
When a web application calls window.open()
in JavaScript, the WKWebView
will call the
- webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:
method on its UIDelegate
.
在该委托方法中,应使用提供给您的WKWebViewConfiguration
创建一个新的WKWebView
.如果您在屏幕上显示此新的WKWebView
,它将以正确的内容加载.
In that delegate method you should create a new WKWebView
with the WKWebViewConfiguration
that is given to you. If you present this new WKWebView
on screen, it will load with the correct content.
This is documented in the WKUIDelegate documentation, although it is not very explicit that this is called as a result of window.open()
.
这篇关于WKWebView和window.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!