【问题标题】:WKWebView popup is not working in MacOS app [closed]WKWebView 弹出窗口在 MacOS 应用程序中不起作用 [关闭]
【发布时间】:2021-08-07 08:29:08
【问题描述】:

我的 MacOS 应用程序中有 WKWebView。我在其中使用的 URL 在单击预览按钮时会弹出一个模型。但是每当我点击预览按钮时,什么都没有发生。我尝试添加以下首选项代码,但没有成功。

   let preferences = WKPreferences()
   preferences.javaScriptEnabled = true
   preferences.javaScriptCanOpenWindowsAutomatically = true

【问题讨论】:

    标签: swift macos wkwebview


    【解决方案1】:

    注意:您将无法点击网站上的几个链接,因为它们是 HTTP 而不是 HTTPS。 WKWebView 默认阻止所有不安全的 HTTP 请求。

    要绕过,只需在 info.plist 文件中添加 NSExceptionAllowsInsecureHTTPLoads 为 true。

    override func loadView() {
        webView = WKWebView(frame: .zero, configuration: WKWebViewConfiguration())
        webView?.uiDelegate = self
        webView?.navigationDelegate = self
        view = webView
    }
    
    func webView(_: WKWebView, createWebViewWith _: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures _: WKWindowFeatures) -> WKWebView? {
        self.webView?.load(navigationAction.request)
        return nil
    }
    

    【讨论】:

    • 我试过这个委托方法,但navigationAction.request.url 为零。
    • 我已经更新我的答案检查它
    猜你喜欢
    • 2013-11-14
    • 1970-01-01
    • 2013-05-22
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    相关资源
    最近更新 更多