此参考页面介绍了中间 iframe 支持 JavaScript API,一键快捷功能会使用该 API 在后续用户体验中操纵中间 iframe。
如需了解如何使用中间 iframe,请参阅使用 iframe 集成一键快捷功能指南。
下表列出了所有可用方法及其行为。
| 方法 | |
|---|---|
verifyParentOrigin |
执行父级来源验证 |
notifyParentClose |
通知父级框架跳过一键登录用户体验流程 |
notifyParentDone |
通知父级框架一键快捷登录用户体验流程已完成 |
notifyParentResize |
通知父框架调整中间 iframe 的大小 |
notifyParentTapOutsideMode |
当用户点击中间 iframe 外部时,通知父级框架是否取消中间 iframe |
加载 Intermediate Iframe Support JavaScript 库
将以下代码段放入您要加载中间 iframe 的任何 HTML 网页中:
<script src="https://accounts.google.com/gsi/intermediatesupport"></script>
方法:google.accounts.id.intermediate.verifyParentOrigin
google.accounts.id.intermediate.verifyParentOrigin 方法会执行父级来源验证。请参阅以下方法代码示例:
google.accounts.id.intermediate.verifyParentOrigin(
origins, verifiedCallback, verificationFailedCallback)
以下代码示例展示了如何仅在父级来源经过验证后才显示界面:
<script>
window.onload = () => {
google.accounts.id.intermediate.verifyParentOrigin(
"https://example.com", showUI, showError);
};
</script>
下表列出了这些参数:
| 参数 | |
|---|---|
origins |
允许嵌入中间 iframe 的源。 |
verifiedCallback |
当允许当前父级源嵌入中间 iframe 时触发的 JavaScript 回调方法。 |
verificationFailedCallback |
当当前父级来源不允许嵌入中间 iframe 时触发的 JavaScript 回调方法。 |
来源
允许嵌入中间 iframe 的源。如需了解详情,请参阅下表:
| 类型 | 是否必须提供 | 示例 |
|---|---|---|
| 字符串、字符串数组或函数 | 可选 | allowed_parent_origin: "https://example.com" |
下表列出了支持的值类型及其说明。
| 值类型 | ||
|---|---|---|
string |
单个网域 URI。 | "https://example.com" |
string array |
网域 URI 数组。 | "https://news.example.com,https://local.example.com" |
verifiedCallback
此字段是一个 JavaScript 回调方法,在允许当前父级源嵌入中间 iframe 时触发。
verificationFailedCallback
此字段是一个 JavaScript 回调方法,当当前父级来源不允许嵌入中间 iframe 时触发。
方法:google.accounts.id.intermediate.notifyParentClose
google.accounts.id.intermediate.notifyParentClose 方法会在跳过一键快捷功能用户体验流程时通知父级框架关闭中间 iframe。请参阅以下方法代码示例:
google.accounts.id.intermediate.notifyParentClose()
方法:google.accounts.id.intermediate.notifyParentDone
google.accounts.id.intermediate.notifyParentDone 方法会通知父级框架关闭中间 iframe 并刷新登录状态。请参阅以下该方法的代码示例:
google.accounts.id.intermediate.notifyParentDone()
方法:google.accounts.id.intermediate.notifyParentResize
google.accounts.id.intermediate.notifyParentResize 方法会通知父级框架调整中间 iframe 的大小。请参阅以下方法的代码示例:
google.accounts.id.intermediate.notifyParentResize(height)
高度
新高度(以像素为单位)。这是必填字段。该值必须是非负数。
如果 height 参数大于 0,则中间 iframe 会设置为新高度。如果 height 参数为 0,则中间 iframe 将变为不可见。隐藏的 iframe 未关闭。之后,可以通过另一个 resize 方法调用来显示该广告。
方法:google.accounts.id.intermediate.notifyParentTapOutsideMode
google.accounts.id.intermediate.notifyParentTapOutsideMode 方法会通知父级框架,当用户点击中间 iframe 外部时,是否取消中间 iframe。请参阅以下方法代码示例:
google.accounts.id.intermediate.notifyParentTapOutsideMode(cancel)
取消
此必需布尔值用于指明当用户点击中间 iframe 外部时是否取消中间 iframe。