如何从wkwebview调用javascript函数?

时间:2018-03-07 10:05:24

标签: javascript ios swift webview

我使用的是 protected void Page_Load(object sender, EventArgs e){ //SolidCP.Providers.ServiceProviderSettings objServerSetiing = new SolidCP.Providers.ServiceProviderSettings() { // code stuff.. }; SolidCP.Providers.RemoteServerSettings objSetting = new SolidCP.Providers.RemoteServerSettings() { ADUsername = "rrrrr", ADPassword= "33333333", ADEnabled = true }; SolidCP.Server.Client.ServerProxyConfigurator objConfig = new SolidCP.Server.Client.ServerProxyConfigurator() { ServerUrl = "22.22.22.22", ServerPassword = "33333333",ServerSettings = objSetting }; objConfig.Configure(objPackage); } ,当用户点按内部时,我需要发回给网络服务器信息以允许它做出一些操作:

第一个名为wkwebview的函数位于我的完成处理程序操作表alert:

btDialogClicked("ok" / "cancel")

我的案例中的第二个叫Extension.createActionSheet(title: body["title"], message: body["message"], validationMessage: body["buttonOK"], cancelMessage: body["buttonCancel"], controller: self, completionHandler: nil) ,它位于我枚举的后面的案例中:

btBackClicked

我如何实现这两个。

1 个答案:

答案 0 :(得分:1)

evaluateJavaScript()将允许您在WebView加载的网页上运行任何JavaScript。喜欢:

webView.evaluateJavaScript("document.getElementById('myJSTextField').innerText") { (result, error) in
    guard error == nil, let result = result else {
       print("Error!")
    }
    print(result)
}