16

UIWebview has (had?) an extremely useful function that enabled access to javascript variables from Swift.

func stringByEvaluatingJavaScriptFromString(_ script: String) -> String?

Does WKWebview have an equivalent function or idiom enabling access to javascript variables from Swift?

lolololol ol
  • 848
  • 1
  • 8
  • 18

1 Answers1

24

Yes, WKWebView has the evaluateJavaScript method that lets you run JavaScript code and access JavaScript variables.

func evaluateJavaScript(_ javaScriptString: String, 
  completionHandler: ((Any?, Error?) -> Void)? = nil)
Pang
  • 9,564
  • 146
  • 81
  • 122
Shin
  • 289
  • 2
  • 5