<!--
{
  "availability" : [
    "iOS: 2.0.0 - 12.0.0",
    "iPadOS: 2.0.0 - 12.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIWebView/stringByEvaluatingJavaScript(from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIWebView(im)stringByEvaluatingJavaScriptFromString:"
  },
  "title" : "stringByEvaluatingJavaScript(from:)"
}
-->

# stringByEvaluatingJavaScript(from:)

Returns the result of running a JavaScript script.

```
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 <doc://com.apple.documentation/documentation/WebKit/WKWebView/evaluateJavaScript(_:completionHandler:)> method from the <doc://com.apple.documentation/documentation/WebKit/WKWebView> class. Legacy apps should adopt that method if possible.

> Important:
> The ``doc://com.apple.uikit/documentation/UIKit/UIWebView/stringByEvaluatingJavaScript(from:)`` method waits synchronously for JavaScript evaluation to complete. If you load web content whose JavaScript code you have not vetted, invoking this method could hang your app. Best practice is to adopt the <doc://com.apple.documentation/documentation/WebKit/WKWebView> class and use its <doc://com.apple.documentation/documentation/WebKit/WKWebView/evaluateJavaScript(_:completionHandler:)> method instead.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)