使用默认的“正在加载”图片

此功能不适用于 AMPHTML 广告

在加载广告的剩余部分时(尤其是当广告比较大时),展示一张图片通常会非常有用。

1. 设置“正在加载”图片

将 ID 为“loading”的 div 添加到 HTML 中:

<body style="visibility: hidden;">
   <div id="loading" class="loading-image">
       Loading...
   </div>
   <gwd-google-ad id="gwd-ad" polite-load="">
       ...
   </gwd-google-ad>
</body>

2. 停止展示“正在加载”图片

要隐藏或移除“正在加载”图片,您只需向 handleAdInitialized 函数添加代码即可。系统会在广告初始化之后调用此方法。如果您已启用礼让加载,系统则会在分派 PAGE_LOADED(启动器)事件之后调用此方法。

隐藏“正在加载”图片

以下突出显示的代码将会隐藏“正在加载”图片:

/**
 * Handles the event that is dispatched after the Ad has been
 * initialized and before the default page of the Ad is shown.
 */
function handleAdInitialized(event) {
  // This marks the end of the polite load phase of the Ad. If a
  // loading image was shown to the user, this is a good place to
  // remove it.
  document.getElementById('loading').style.display = 'none';
}

移除“正在加载”图片

以下突出显示的代码将会移除“正在加载”图片:

/**
 * Handles the event that is dispatched after the Ad has been
 * initialized and before the default page of the Ad is shown.
 */
function handleAdInitialized(event) {
  // This marks the end of the polite load phase of the Ad. If a
  // loading image was shown to the user, this is a good place to
  // remove it.
  document.body.removeChild(document.getElementById('loading'));
}

该内容对您有帮助吗?

您有什么改进建议?
搜索
清除搜索内容
关闭搜索框
主菜单
12261796064609028038
true
搜索支持中心
true
true
true
true
true
5050422
false
false