【问题标题】:Can't run or embed google Web App无法运行或嵌入 google Web App
【发布时间】:2018-06-09 21:19:28
【问题描述】:

我只是在学习 google 脚本,想从制作一个简单的 hello world 开始。我已经完成了谷歌的教程,当我在发布网络应用程序弹出窗口上单击“测试此代码”时,代码运行,我得到了基本的 hello world 结果。伟大的。但是当我将提供的 URL 粘贴到浏览器中或将相同的 URL 嵌入到谷歌网站时,我只会得到一个空白页。

如何运行网络应用程序?我错过了什么吗?

code.gs:

function doGet() {
      var html= HtmlService
          .createTemplateFromFile('Index');
          html.name = 'David';         
          return html.evaluate();
    }  

index.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>Hi <?=name?>!</b>
  </body>
</html>

来自基本的 PHP 背景,我习惯于访问 .php 文件的 URL,然后砰的一声,消失了……我很困惑。

【问题讨论】:

  • 这个问题和PHP有什么关系?
  • 我知道,很奇怪,对吧?那是一个建议的标签...
  • @DavidTonkin — 建议是建议。如果它们错了,请不要使用它们!

标签: google-apps-script


【解决方案1】:

我认为这应该可行

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>Hi <?!=name?></b>
  </body>
</html>

https://developers.google.com/apps-script/guides/html/templates#force-printing_scriptlets

文件名也应该完全相同 我认为索引和索引不起作用

【讨论】:

    【解决方案2】:

    https://stackoverflow.com/a/40843413/6288442

    Google 最近刚刚启用了此功能。它已经下一个 “功能请求”状态很长一段时间。链接在这里

    您现在可以显式定义 X-Frame-Options。

    要允许在另一个域下嵌入,该选项应该是 HtmlService.XFrameOptionsMode.ALLOWALL

    关于该主题的 Google 文档:

    https://developers.google.com/apps-script/reference/html/html-output#setXFrameOptionsMode(XFrameOptionsMode)

    例子:

    函数 doGet() { 返回 HtmlService.createTemplateFromFile('form.html') .evaluate() // 评估必须在设置沙盒模式之前进行 .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); }

    希望这会有所帮助!

    【讨论】:

    • 是的,修复了平面 URL 和嵌入 URL .....谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 2020-01-07
    • 2011-08-27
    • 2012-07-21
    • 2017-11-14
    • 1970-01-01
    相关资源
    最近更新 更多