嵌入到iFrame中后,Google Apps脚本不会加载 [英] Google Apps Script does not load when embedded into iFrame

查看:231
本文介绍了嵌入到iFrame中后,Google Apps脚本不会加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的Google Apps脚本WebApp嵌入到另一个域的iFrame中,但是该Webapp未加载,并且只能看到白屏. webinspector中也没有错误.

I am trying to embed my Google Apps Script WebApp into an iFrame on another domain but the webapp is not loaded and I only see a white screen. There is also no error in the webinspector.

该Webapp的发布日期为:以m e身份执行,并且 Access在给定域内有任何人.

The Webapp is published with: Execute as me and Access has anyone within Given Domain.

根据实现了我的doGet方法,如下所示:

According to this I implemented my doGet method like this:

function doGet(e) {
 return HtmlService
 .createHtmlOutputFromFile('html/index')
 .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

IFrame如下所示:

and the IFrame looks like this:

<iframe src="https://script.google.com/a/my_domain/macros/s/ADjidojcojv/exec" title="test" width="558" height="300"></iframe>

当用户登录到Google时,将显示webapp.但是,当用户未使用account.google.com refused to connect

When the user is logged into Google the webapp is displayed. However when the user is not logged in a grey image with account.google.com refused to connect

我认为原因是存在无法重定向到Google登录的重定向.此外,在这种情况下,还有另一个重定向到SAML SSO应用程序.因此,当您正常登录google时,您将重定向到SAML SSO登录名.

I think the reason is that there is a redirect to the google sign in which does not allow to be displayed. Furthermore in this case there is also another redirect to a SAML SSO application. So when you normally sign in into google you will redirect to the SAML SSO login.

我在这里有什么选择?

我发现某人的完全一样问题和一种可能的解决方案.显然,没有简单的方法可以做到这一点……

I found someone with the exact same problem and one possible solution. Apparently there is no easy way of doing this...

推荐答案

发布具有访问权限:任何人"的Web应用程序时,最终用户需要登录.否则,该用户将被重定向到Google登录页面. Google的登录页面不允许对其进行格式化.如果您已登录,则该Web应用程序不会重定向到Google的登录页面,并且不会出现此错误,否则会出现.

When publishing web-apps with access: "anyone", it is needed for the end user to be logged in. Otherwise, the user is redirected to Google login page. Google's login page does not allow itself to be iframed. If you're logged in, the web app isn't redirected to Google's login page and this error doesn't appear, else it appears.

  • 预先警告用户必须登录
  • 使用访问权限发布:甚至匿名的任何人"
  • 如果这不可能,则可以使用window.length(跨源可访问的少数几个属性之一)来检测iframed页面是否已加载窗口,如果页面拒绝连接,则为0.在Web应用程序中大于0,因为您的页面经过了iframed.然后可以将用户重定向到登录页面.
  • Warn users beforehand that they must login
  • Publish using access: "Anyone even anonymous"
  • If that's not possible, It is possible to detect whether the iframed page has window loaded or not using window.length(one of the few properties that is accessible cross origin), which will be 0 if page refused to connect and more than 0 in a web-app, because your page is iframed. Then it is possible to redirect the user to the login page.
<!DOCTYPE html>
<html>
  <body>
    body
    <iframe
      src="https://script.google.com/macros/s/[SCRIPT_ID]/exec"
      >Loading
    </iframe>
    <script>
      const main = (() => {
        console.log("loading page");
        const f = document.querySelector("iframe");
        f.onload = (e) => {
          console.log("iframe onload");
          const fw = f.contentWindow;
          if (fw.length > 0) console.info("logged in");
          else {
            alert("Please Login!");
            window.location = "https://accounts.google.com";
          }
        };
      })();
    </script>
  </body>
</html>

参考文献:

  • 相同的来源政策
  • References:

    • Same origin policy
    • 这篇关于嵌入到iFrame中后,Google Apps脚本不会加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆