authentication - 如何以编程方式关闭谷歌一键登录 iframe?

标签 authentication iframe yolo

我有一个登录表单,其中我使用谷歌一键登录。我正在以角度开发此功能。因此,当我进入登录页面时,google 一键登录 iframe 将加载到页面中。但当我进入另一个页面时,实际问题出现了,我的 google 一键登录 iframe 保持在页面一角。

我已经尝试使用 jquery 删除 iframe,但在这种情况下,iframe 已成功删除,但当通过从一个页面导航到另一页面再次加载登录页面时,iframe 不会再次显示。

所以我认为,如果我务实地触发 iframe 关闭按钮的关闭事件,那么我的问题就解决了。但我找不到任何官方文档。为了它。

有什么方法可以实用地关闭该 iframe 吗?

最佳答案

这是我在更多谷歌搜索后找到的答案。

首先在组件上Delcare:

declare const googleyolo: any;

我将 iframe 添加到登录表单中,如下所示:

    const hintPromise = googleyolo.hint({
      supportedAuthMethods: [
        "https://accounts.google.com"
      ],
      supportedIdTokenProviders: [
        {
          uri: "https://accounts.google.com",
          clientId: "Your google yolo client id"
        }
      ]
    }).then((credential) => {
          // automatically Call this function after click on one account
      }
    }, (error) => {
      console.log('error', error);
    });

    const bodyObserver = new MutationObserver(mutationsList => {
      mutationsList.forEach((mutation: any) => {
        mutation.addedNodes.forEach((node: any) => {
          if (node.nodeName === 'IFRAME' && node.src.includes('smartlock.google.com/iframe/')) {
            bodyObserver.disconnect();
            node.classList.add('google-inserted-frame');
            node.setAttribute('id', 'googleYoloIframe');
          }
        });
      });
    });
    bodyObserver.observe(window.document.body, {
      childList: true
    });
  }

这里以编程方式忽略 IFrame :

var iframe = $('#googleYoloIframe');
if(iframe.length > 0){
  googleyolo.cancelLastOperation();
}

关于authentication - 如何以编程方式关闭谷歌一键登录 iframe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59356543/

相关文章:

ruby-on-rails - Google Apps 和 Rails 中的 Open ID 身份验证 - 安全性

authentication - 如何使用 PAM 对用户进行身份验证?

android - 如何在谷歌操作、移动应用、后端服务器和 Firebase 身份验证之间关联用户帐户?

authentication - Web应用程序中用户的多个身份验证源的数据库结构

javascript - 通过javascript动态获取iframe的内容高度

javascript - 一个链接在同一页面上打开两个 Iframe 目标

javascript - 如何避免加载 iframe 源

yolo - 了解暗网的 yolo.cfg 配置文件

python - 我想在 Google colab 上训练 YOLOv3 Darknet 对象检测模型期间绘制 mAP 和损失图

opencv - 如何得到YOLOv5模型的预测图像?