WKWebView和window.open [英] WKWebView and window.open

查看:97
本文介绍了WKWebView和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆