简体   繁体   中英

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:

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:

<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':

<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. In function 'newPresentation' there are other HTML dialogs that are called up.

But, when another user runs the script, this HTML dialog doesn't close itself. Even though it doesn't close itself, the rest of the script is executed normally. I have already shared the spreadsheet with another user, with edit privileges. Both me and the other user are logged in a Google Account.

Some idea how to fix that problem?

PS.: Sorry for some grammatical errors, but I'm not fluent in english.

Try this:

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

and put a return at the end of newPresentation();

Another possibility is to try using the dummy dialog described here: 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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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