> ## Documentation Index
> Fetch the complete documentation index at: https://rpa.bazhuayu.com/helpcenter/llms.txt
> Use this file to discover all available pages before exploring further.

# 在网页上执行JavaScript函数

## 指令说明

**描述：** 在指定的网页中执行一段JavaScript脚本，同时获取脚本的执行结果。

## 参数说明

<Tabs>
  <Tab title="常规">
    <img src="https://mintcdn.com/bazhuayu-rpa-docs/2nc_spg9_b4MXqPM/helpcenter/commands/web-automation/images/web-js-01.png?fit=max&auto=format&n=2nc_spg9_b4MXqPM&q=85&s=4f4b81b907578ea7c94751ed9d63dede" alt="在网页上执行JavaScript函数指令参数面板" width="645" height="485" data-path="helpcenter/commands/web-automation/images/web-js-01.png" />

    | 参数               | 说明                                         |
    | ---------------- | ------------------------------------------ |
    | **网页对象**         | 选择一个之前通过【打开网页】或【获取已打开的网页对象】指令创建的网页对象       |
    | **JavaScript函数** | 输入要执行的JavaScript脚本代码，直接写在函数体内，即{}内，需要保留函数名 |
  </Tab>

  <Tab title="高级">
    本指令暂无高级参数。
  </Tab>
</Tabs>

## 使用示例

<img src="https://mintcdn.com/bazhuayu-rpa-docs/2nc_spg9_b4MXqPM/helpcenter/commands/web-automation/images/web-js-02.png?fit=max&auto=format&n=2nc_spg9_b4MXqPM&q=85&s=58cfaebb65f77c3b7ebedfce4ca3b02f" alt="在网页上执行JavaScript函数使用示例 - 流程搭建" width="956" height="188" data-path="helpcenter/commands/web-automation/images/web-js-02.png" />

<img src="https://mintcdn.com/bazhuayu-rpa-docs/2nc_spg9_b4MXqPM/helpcenter/commands/web-automation/images/web-js-03.png?fit=max&auto=format&n=2nc_spg9_b4MXqPM&q=85&s=cb7eac89ae8a2b39fce3f414be1d126f" alt="在网页上执行JavaScript函数使用示例 - JavaScript函数" width="660" height="491" data-path="helpcenter/commands/web-automation/images/web-js-03.png" />

**该流程执行逻辑：**

使用【获取已打开的网页对象】指令将已打开的网页作为网页对象

使用【在网页上执行JavaScript函数】指令执行JavaScript函数，该函数的作用是获取当前网页的url。案例JS代码是：

```javascript theme={null}
function getUrl(element, input){
  var dataUrl = document.URL;
  return dataUrl;
}
```

将JavaScript脚本的执行结果打印在控制台中

### 效果展示

JavaScript脚本在目标网页上成功执行，并返回执行结果。

<img src="https://mintcdn.com/bazhuayu-rpa-docs/2nc_spg9_b4MXqPM/helpcenter/commands/web-automation/images/web-js-04.png?fit=max&auto=format&n=2nc_spg9_b4MXqPM&q=85&s=525c73c84a8ba9d8ab112129df4e93b9" alt="在网页上执行JavaScript函数使用示例 - 效果展示" width="1343" height="171" data-path="helpcenter/commands/web-automation/images/web-js-04.png" />

<Info>
  使用指令过程中遇到问题？前往 [八爪鱼RPA 开发者社区问答板块](https://rpa.bazhuayu.com/community/questions) 提问，获取官方与社区帮助。
</Info>
