关闭包含表单的App脚本侧边栏 [英] Closing an App Script sidebar containing a form

查看:96
本文介绍了关闭包含表单的App脚本侧边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Google Apps Script running a html-form in the sidebar. The form-answers are used to generate documents. My problem is that I want to close the sidebar when the program has completed (after clicking Submit).

<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()末尾的侧边栏?

The program runs as intended if I remove the withSuccessHandler, otherwise it doesn't. Are there a way for me to close the sidebar at the end of doStuff()?

文档:边栏可以通过致电google自行关闭. HTML服务界面的客户端中的script.host.close()或UI服务界面中的UiInstance.close().侧栏不能由其他界面关闭,只能由用户或自己关闭.

Documentation: The sidebar can close itself either by calling google.script.host.close() in the client side of an HTML-service interface or UiInstance.close() in a UI-service interface. The sidebar cannot be closed by other interfaces, only by the user or itself.

UiInstance被标记为已弃用.

UiInstance is marked Deprecated.

推荐答案

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

The onclick() attribute can have multiple functions in it. You can put the google.script.host.close() statement after all the code. Just make sure to put a semi-colon at the end of all the google.script.run stuff:

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

您将很多代码打包到onclick()属性中.您可以有一个单独的功能:

Your packing a lot of code into the onclick() attribute. You could have a separate function:

onclick="serverCall();"

window.serverCall = function() {
  google.script.run
    .withFailureHandler(fail)
    .doStuff(this.parentNode);

  google.script.host.close();
};

这篇关于关闭包含表单的App脚本侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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