代码之家  ›  专栏  ›  技术社区  ›  Nitesh

在Webview上获取页面加载事件

  •  1
  • Nitesh  · 技术社区  · 6 年前

    示例URL: https://unifiedportal-mem.epfindia.gov.in/memberinterface/

    如何完成这一页的正面?如何获取加载后的消息“UAN is not Active”。

    webView的这个didFinish函数在这种情况下不起作用,因为页面已经加载。

        func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!{
    }
    

    在下面的方式尝试,但没有回应。明白了吗

    Error Domain=WKErrorDomain Code=5“JavaScript执行返回不支持类型的结果”UserInfo={NSLocalizedDescription=JavaScript执行返回不支持类型的结果}

    let s = """
    var open = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        this.addEventListener("load", function() {
            var message = {"status" : this.status, "responseURL" : this.responseURL}
            webkit.messageHandlers.handler.postMessage(message);
        });
        open.apply(this, arguments);
    };
    """
                            weakSelf.webView.configuration.userContentController.removeScriptMessageHandler(forName: "myInterface") // to delete existing
                            weakSelf.webView.configuration.userContentController.add(weakSelf as WKScriptMessageHandler, name: "myInterface")
                            weakSelf.webView?.evaluateJavaScript(s, completionHandler: {(string,error) in
                                print(error ?? "no error")
                            })
    
    0 回复  |  直到 6 年前