Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView and 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.

Is there a workaround for this?

I tried setting javaScriptCanOpenWindowsAutomatically preference to true but that didn't seem to help

like image 705
Bret Avatar asked Oct 17 '15 18:10

Bret


People also ask

What is the difference between UIWebView and WKWebView?

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.

Is WKWebView the same as Safari?

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.

What is a WKWebView?

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.

Is WKWebView secure?

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.


1 Answers

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().

like image 187
Stefan Arentz Avatar answered Nov 11 '22 08:11

Stefan Arentz