简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM