加载 Google 网站后自动运行 Google 应用程序脚本?

2024-01-04

我编写了一个 Apps 脚本,它采用电子表格并将其转换为 Google 表单。我想在我的谷歌网站上显示表单;但是,我希望表单在每次打开网站时自动刷新,这样如果电子表格发生更改,表单在显示时也会更新。本质上,我希望脚本在打开 Google 网站时自动运行 - 知道如何做到这一点吗?

另外,作为旁注(不太重要),有没有什么方法可以将脚本合并到谷歌网站中而不将其显示为小工具?我不想显示脚本,我只想让它在后台运行。


您可以在站点加载时间接运行 Apps 脚本函数,方法是使用 HTML 服务创建独立的 Web 应用程序,发布它,然后将window.onload进入脚本标签:

<script>
  window.onload = function() {
    console.log('Onload ran. ');//Open the browser console log to see debug messages

  };
</script>

然后使用google.script.run运行服务器功能:

<script>
  window.onload = function() {
    console.log('hah! it ran. ');
    google.script.run
      .withSuccessHandler(run_This_On_Success)
      .gsServerFunction();
  };

 window.run_This_On_Success = function(the_Return) {
   console.log('was successful!: ' + the_Return);
 };

Code.gs

function gsServerFunction() {
  return true;
};

索引.html

<!DOCTYPE html>
<html>
  <body>
    This is the body


    <script>
      window.onload = function() {
        console.log('hah! it ran. ');
        google.script.run
          .withSuccessHandler(wuzSugzezvul)
          .gsServerFunction();
       };

       window.wuzSugzezvul = function() {
         console.log('was successful!');
       };
    </script>
  </body>
</html>

删除应用程序脚本小工具的边框和标题,使其非常小,并且不要放入任何要在 HTML 中显示的文本。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

加载 Google 网站后自动运行 Google 应用程序脚本? 的相关文章

随机推荐