【问题标题】:Closing an App Script sidebar containing a form关闭包含表单的 App Script 侧边栏
【发布时间】:2016-03-14 18:10:37
【问题描述】:

我有一个在侧边栏中运行 html 表单的 Google Apps 脚本。 表单答案用于生成文档。我的问题是我想在程序完成后关闭侧边栏(点击提交后)。

<form id="myForm">
    <input name="name" type="text"/>
    <input type="button" value="Submit" onclick="google.script.run.withFailureHandler(fail).
                                        withSuccessHandler(google.script.host.close()).
                                        doStuff(this.parentNode)"/>

</form>

如果我删除了 withSuccessHandler,程序会按预期运行,否则不会。有没有办法让我在 doStuff() 结束时关闭侧边栏?

Documentation:侧边栏可以通过在 HTML 服务接口的客户端调用 google.script.host.close() 或在 UI 服务接口调用 UiInstance.close() 来自行关闭。侧边栏不能被其他界面关闭,只能由用户或自己关闭。

UiInstance 被标记为已弃用。

【问题讨论】:

    标签: html forms google-apps-script server client


    【解决方案1】:

    onclick() 属性可以包含多个功能。您可以将google.script.host.close() 语句放在所有代码之后。只需确保在所有 google.script.run 内容的末尾添加一个分号即可:

    <input type="button" value="Submit" 
      onclick="google.script.run.withFailureHandler(fail)
      .doStuff(this.parentNode); google.script.host.close();"/>
    

    您将大量代码打包到 onclick() 属性中。你可以有一个单独的功能:

    onclick="serverCall();"
    
    window.serverCall = function() {
      google.script.run
        .withFailureHandler(fail)
        .doStuff(this.parentNode);
    
      google.script.host.close();
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-26
      • 2013-02-19
      相关资源
      最近更新 更多