我有一个在侧边栏中运行 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 服务接口(interface)的客户端中调用 google.script.host.close() 或在 UI 服务接口(interface)中调用 UiInstance.close() 自行关闭。侧边栏不能被其他界面关闭,只能由用户或自己关闭。
UiInstance 被标记为“已弃用”。
最佳答案
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();
};
关于html - 关闭包含表单的应用程序脚本侧边栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34179339/