> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/guang-gao/loadfullscreenad.md).

# loadFullScreenAd

### 功能说明

会预先加载集成全屏广告。优先显示 Toss Ad，在无法使用的环境中会自动切换为 AdMob，因此可以稳定展示广告。显示广告前务必调用。

会根据 Toss App 版本而有不同的行为：

| Toss App 版本                   | 支持功能                                            |
| ----------------------------- | ----------------------------------------------- |
| `5.239.0` 及以上                 | Toss Ad + AdMob 集成（优先 Toss Ad，无法使用时自动切换为 AdMob） |
| `5.227.0` 及以上 \~ `5.239.0` 未满 | 仅显示 AdMob 广告                                    |
| `5.227.0` 未满                  | 不支持                                             |

调用前 `loadFullScreenAd.isSupported()`可通过它确认是否支持。

### 类型

```ts
loadFullScreenAd(params: LoadFullScreenAdParams): () => void;
```

**参数**

```ts
type LoadFullScreenAdParams = {
  options: LoadFullScreenAdOptions;
  onEvent: (event: LoadFullScreenAdEvent) => void;
  onError: (error: unknown) => void;
};

type LoadFullScreenAdOptions = {
  /** 广告组 ID。请填写在 App in Toss 控制台中获取的值。 */
  adGroupId: string;
};

type LoadFullScreenAdEvent = {
  type: "loaded";
};
```

**响应**

用于解除 AppBridge 回调的函数（`() => void`）会被返回。

### 错误

如果广告加载失败 `onError` 错误会通过回调传递。若在不支持的版本中调用 `onError`则会传递错误，因此在调用前 `isSupported()`请通过确认。

### 示例代码

```js
import { Ads } from "@apps-in-toss/web-framework";

let isAdLoaded = false;

function prepareAd() {
  if (!loadFullScreenAd.isSupported()) {
    console.warn("当前环境中无法使用全屏广告。");
    return;
  }

  const cleanup = loadFullScreenAd({
    options: { adGroupId: "AD_GROUP_ID" },
    onEvent: (event) => {
      if (event.type === "loaded") {
        console.log("广告加载完成");
        isAdLoaded = true;
        cleanup();
      }
    },
    onError: (error) => {
      console.error("广告加载失败：", error);
      cleanup();
    },
  });
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/guang-gao/loadfullscreenad.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
