It appears that a lot of links on websites use window.open in their onclick handlers but WKWebView seems to completely ignore window.open.
Is there a workaround for this?
I tried setting javaScriptCanOpenWindowsAutomatically preference to true but that didn't seem to help
Difference Between UIWebview and WKWebViewUIWebview is a part of UIKit, so it is available to your apps as standard. You don't need to import anything, it will we there by default. But WKWebView is run in a separate process to your app,. You need to import Webkit to use WKWebView in your app.
WKWebView - This view allows developers to embed web content in your app. You can think of WKWebView as a stripped-down version of Safari. It is responsible to load a URL request and display the web content. WKWebView has the benefit of the Nitro JavaScript engine and offers more features.
Overview. A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.
The WKWebView is a modern API applying all the modern web security mechanisms, it's still maintained by Apple and gets updates. The good thing about WKWebView is that it does out-of-process rendering, so if the attackers find a memory corruption vulnerability in it, your application's process is still isolated.
When a web application calls window.open()
in JavaScript, the WKWebView
will call the - webView:createWebViewWithConfiguration:forNavigationAction:windowFeatures:
method on its UIDelegate
.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With