【问题标题】:Close modal after progress complete automatically进度完成后自动关闭模态
【发布时间】:2021-03-12 11:56:06
【问题描述】:

我想使用 GAS 在 Google 幻灯片中显示进度或加载屏幕。 下面的脚本工作正常,但我不知道如何删除 x 关闭图标以及如何在我的过程完成后自动关闭模式(我在内部使用 GAS)。

show_progress.gs

var htmlOutput = HtmlService
                    .createHtmlOutput('<p>Loading...</p><style>.modal-dialog-title-close{display:none;}</style')
                .setWidth(250)
                .setHeight(300);

SlidesApp.getUi().showModalDialog(htmlOutput, 'Genera progetto');

...............
.............
..................
..............

google.script.host.close();

【问题讨论】:

  • 我认为这在演示文稿中不起作用。但可以肯定的一件事是 google.script.host.close() 是客户端功能而不是服务器端
  • 如果你想关闭一个对话框,你总是可以用 window.onload 中的 google.script.host.close() 替换另一个自动关闭对话框

标签: google-apps-script google-slides-api google-slides


【解决方案1】:

修改后的脚本

这是一个使用setTimeout(callback, time)的示例

function myFunction() {

  var html = `
  <p>Loading...</p>
  <script>
    setTimeout(google.script.host.close(), 3000);
  </script>
  `

  var htmlOutput = HtmlService
                .createHtmlOutput(html)
                .setWidth(250)
                .setHeight(300);
  SlidesApp.getUi().showModalDialog(htmlOutput, 'Genera progetto');
}

如您所见,google.script.host.close() 需要作为 html 服务的一部分在客户端调用。 3000毫秒后作为回调函数调用。

不过,我不确定您的“过程”,以及您打算如何触发它。理想情况下,您从客户端 html 触发该过程,操作如下:

google.script.run.doSomething();

.gs 文件中的函数如下所示:

function doSomething() {
   Utilities.sleep(10000);
   return "Complete";
}

如果你想让某件事在完成后发生,那么从客户端 html 你:

function onSuccess(return){
    console.log(return);
    google.script.host.close();
}

google.script.run.withSuccessHandler(onSuccess).doSomething()

所以你的完整函数可能看起来像这样:

function myFunction() {

  var html = `
  <p>Loading...</p>
  <script>
    function onSuccess(return){
        console.log(return);
        google.script.host.close();
    }
    google.script.run.withSuccessHandler(onSuccess).doSomething()
  </script>
  `

  var htmlOutput = HtmlService
                .createHtmlOutput(html)
                .setWidth(250)
                .setHeight(300);
  SlidesApp.getUi().showModalDialog(htmlOutput, 'Genera progetto');
}

请记住,从客户端开始“Genera progetto”过程听起来更好。否则无法从 .gs 文件与客户端 html 进行通信。

参考文献

【讨论】:

    猜你喜欢
    • 2010-10-18
    • 1970-01-01
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多