---
id: "M:cAlgo.API.WebView.ExecuteScript(System.String)"
kind: "method"
type: "T:cAlgo.API.WebView"
url: "https://help.ctrader.com/ctrader-algo/references/Controls/WebView/ExecuteScript/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# WebView.ExecuteScript

Member of [WebView](https://help.ctrader.com/ctrader-algo/references/Controls/WebView/index.md).

## ExecuteScript(string javaScript)

Executes JavaScript code from the javaScript parameter in the current top level document rendered in the WebView and returns the result. You can only use this method after control is fully loaded and navigation is completed.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Accepted without error but never displayed, so control events such as Click are never raised.
- Cloud: Accepted without error but never displayed, so control events such as Click are never raised.

C#:

```csharp
public ExecuteScriptResult ExecuteScript(string javaScript)
```

Python:

```python
webView.ExecuteScript(javaScript: str) -> ExecuteScriptResult
```

### Parameters

- `javaScript` (`string`, Python `str`): JavaScript code

### Returns

`ExecuteScriptResult` — ExecuteScriptResult

### Examples

C#:

```csharp
var webView = new WebView { Width = 300, Height = 100 };
webView.NavigateToStringAsync("<html><body>Spread monitor</body></html>");
webView.NavigationCompleted += args =>
{
    var result = webView.ExecuteScript("document.title = 'EURUSD'; document.body.innerText");
    if (result != null && result.IsSuccessful)
        Print("Script result: {0}", result.Json);
};
Chart.AddControl(webView);
```

Python:

```python
def on_start(self):
    self.webView = WebView()
    self.webView.NavigateToStringAsync("<html><body>Spread monitor</body></html>")
    self.webView.NavigationCompleted += self.on_navigation_completed
    api.Chart.AddControl(self.webView)

def on_navigation_completed(self, args):
    result = self.webView.ExecuteScript("document.body.innerText")
    if result is not None and result.IsSuccessful:
        api.Print(f"Script result: {result.Json}")
```

