如何在运行时执行javascript函数,加载聊天窗口的函数未执行
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let javascript =
"const params = {typeId: ‘someid’, callback: getContextCallback} loadChatWindow(params)"
evaluateJavascript(javascript, completion:{ _ in })
}
答案 0 :(得分:0)
尝试在valuateJavascriptcompleteHandler中捕获您的错误,以查看您的JavaScript字符串是否正确(如注释中所述,您需要用分号分隔js语句)。同样,评估Javascript是webView的方法,因此应这样调用:
webView.evaluateJavaScript(javascript) { (result, error) in
print(error as? String)}