Instance Method

stringByEvaluatingJavaScript(from:)

Returns the result of running a JavaScript script. Although this method is not deprecated, best practice is to use the evaluateJavaScript(_:completionHandler:) method of the WKWebView class instead.

Declaration

func stringByEvaluatingJavaScript(from script: String) -> String?

Parameters

script

The JavaScript script to run.

Return Value

The result of running the JavaScript script passed in the script parameter, or nil if the script fails.

Discussion

New apps should instead use the evaluateJavaScript(_:completionHandler:) method from the WKWebView class. Legacy apps should adopt that method if possible.