Safari视图控制器中WKWebView Javascript注入的打开结果

时间:2016-03-15 01:46:11

标签: javascript ios xcode swift wkwebview

我有一个WKWebView我用来修改网页,然后让用户与之互动。我希望能够使用javascript注入以编程方式单击按钮(document.getElementById("id").click()),然后在Safari视图控制器中加载生成的网页。我熟悉WKWebViewevaluateJavascript()方法,但我不确定如何将以编程方式触发的按钮单击结果传输到Safari视图控制器。我该怎么做?我首先会使用Safari视图控制器,但似乎不支持注入脚本。

//various other modifications to webpage precede this
//target button is a 'next' button on webpage
//would like to "click" this button and open the next page in safari vc
//The code below opens the next page in WKWebView

let next = "document.getElementById('\(id)').click()"
webView.evaluateJavaScript(next) { (result, error) in
                print("Result: \(result)")
                print("Error: \(error)")
            }

0 个答案:

没有答案