繁体   English   中英

HTML 对话框不会在 Google Scripts 上的共享电子表格中关闭

[英]HTML Dialog don't close in a shared spreadsheet on Google Scripts

我有一个电子表格,它有一个 function 来调用一个 HTML 对话框来选择一些日期:

htmlDate =  HtmlService.createHtmlOutputFromFile('datePicker')
    .setHeight(120)
    .setWidth(550);

SpreadsheetApp.getUi().showModalDialog(htmlDate, 'Select the dates for presentation:');

这是 HTML 代码的一部分,它定义了 datePicker.html 中按钮的操作:

<input type="button" onClick="submitForm()" value="OK" />
<input type="button" onClick=google.script.host.close() value="Cancel" />

这是 HTML 代码的一部分,它调用我的 function 'newPresentation':

<script type="text/javascript">    
    function submitForm() {

      google.script.run.newPresentation(document.forms[0]);
      Utilities.sleep(1000);
      google.script.host.close();

    }        
</script>

问题是:当我运行脚本时,它运行良好。 首先,它调用我的 function 'newPresentation',然后它自行关闭,运行脚本的 rest。 在 function 'newPresentation' 中,还有其他 HTML 对话框被调用。

但是,当另一个用户运行脚本时,此 HTML 对话框不会自行关闭。 即使它没有自行关闭,脚本的 rest 也会正常执行。 我已经与另一个具有编辑权限的用户共享了电子表格。 我和其他用户都登录了 Google 帐户。

一些想法如何解决这个问题?

PS.:对不起,有些语法错误,但我英语不流利。

尝试这个:

google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.newPresentation(document.forms[0]);

并在 newPresentation() 的末尾添加一个 return;

另一种可能性是尝试使用此处描述的虚拟对话框: https://stackoverflow.com/a/55731456/7215091

我不确定问题发生的原因。 在我进行的所有测试中,我使用了同一台计算机,两台 windows 谷歌浏览器(每个登录用户一台)。 我无法解决问题。

之后,我在一台新计算机上进行了测试,只有一个用户登录,脚本运行良好。

显然,可能是与浏览器中的某些缓存有关的一些问题,或者其他什么。 我真的不知道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM