简体   繁体   English

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

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

I have a spreadsheet that has a function to call an HTML dialog to choose some dates:我有一个电子表格,它有一个 function 来调用一个 HTML 对话框来选择一些日期:

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

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

This is the part of the HTML code that defines the actions of buttons in datePicker.html:这是 HTML 代码的一部分,它定义了 datePicker.html 中按钮的操作:

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

And this is the part of HTML code that calls my function 'newPresentation':这是 HTML 代码的一部分,它调用我的 function 'newPresentation':

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

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

    }        
</script>

The problem is that: When I run the script, it works perfectly.问题是:当我运行脚本时,它运行良好。 First, it calls my function 'newPresentation', and then it closes itself, running the rest of the script.首先,它调用我的 function 'newPresentation',然后它自行关闭,运行脚本的 rest。 In function 'newPresentation' there are other HTML dialogs that are called up.在 function 'newPresentation' 中,还有其他 HTML 对话框被调用。

But, when another user runs the script, this HTML dialog doesn't close itself.但是,当另一个用户运行脚本时,此 HTML 对话框不会自行关闭。 Even though it doesn't close itself, the rest of the script is executed normally.即使它没有自行关闭,脚本的 rest 也会正常执行。 I have already shared the spreadsheet with another user, with edit privileges.我已经与另一个具有编辑权限的用户共享了电子表格。 Both me and the other user are logged in a Google Account.我和其他用户都登录了 Google 帐户。

Some idea how to fix that problem?一些想法如何解决这个问题?

PS.: Sorry for some grammatical errors, but I'm not fluent in english. PS.:对不起,有些语法错误,但我英语不流利。

Try this:尝试这个:

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

and put a return at the end of newPresentation();并在 newPresentation() 的末尾添加一个 return;

Another possibility is to try using the dummy dialog described here: https://stackoverflow.com/a/55731456/7215091另一种可能性是尝试使用此处描述的虚拟对话框: https://stackoverflow.com/a/55731456/7215091

I'm not certain of the reason that issue occurs.我不确定问题发生的原因。 In all tests that i haved make, i used the same computer, with two windows of Google Chrome (one for each user logged in).在我进行的所有测试中,我使用了同一台计算机,两台 windows 谷歌浏览器(每个登录用户一台)。 I can't resolv the problem.我无法解决问题。

After that, i have tested in a new computer, with one single user logged in, and the script works perfectly.之后,我在一台新计算机上进行了测试,只有一个用户登录,脚本运行良好。

Aparently, may be some problem related with some cache in browser, or something.显然,可能是与浏览器中的某些缓存有关的一些问题,或者其他什么。 I really don't know.我真的不知道。

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

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