Closing an App Script sidebar containing a form

自闭症网瘾萝莉.ら 提交于 2019-12-11 11:48:37

问题


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>

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()?

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 is marked Deprecated.


回答1:


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();"/>

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();
};


来源:https://stackoverflow.com/questions/34179339/closing-an-app-script-sidebar-containing-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!