window.open()在WKWebView中没有任何效果

时间:2018-04-13 13:57:23

标签: ios swift wkwebview

我试图在WKWebView中打开新标签,但是当我从javascript调用window.open()时(例如使用Safari调试控制台),这没有效果。

我希望它会触发:

func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView?

但事实并非如此。

class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

    var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let contentController = WKUserContentController()

        let config = WKWebViewConfiguration()
        config.userContentController = contentController

        webView = WKWebView(frame: .zero, configuration: config)
        webView.navigationDelegate = self
        webView.uiDelegate = self

        // ... add subview and setup constraints ...

        webView.load(URLRequest(url: someUrl))
    }

    func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
        print("creates webview with")
        return WKWebView()
    }
}

感谢您的帮助。

0 个答案:

没有答案