【问题标题】:How to open a Model Dialog Box inside another Modal Dialog Box in Google Scripts如何在 Google 脚本中的另一个模态对话框中打开一个模态对话框
【发布时间】:2021-10-01 05:36:58
【问题描述】:

我是谷歌脚本的新手,目前我有一个模式对话框,可以在下图中打开一个 html 文件。

我希望能够按下打开仪表板按钮并关闭此框并打开另一个模式对话框,但是我很难弄清楚如何。与普通 html 不同,由于某种原因,我不能使用 href 来引用我的其他 html 文件。我也尝试过关闭模式框,然后调用打开初始对话框的 GS 函数,但是传入新的 html,也无济于事。我假设我在这里遗漏了一些简单的东西,因为这通常是微不足道的,但我不确定我遗漏了什么,任何建议将不胜感激。

代码.gs

    function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Jigs & Tools')
      .addItem('First item', 'displayHtmlViewer')
      .addToUi();
}

function include(filename) {
 return HtmlService.createHtmlOutputFromFile(filename)
        .getContent();
}

function displayHtmlViewer(file = "index"){
  var html = HtmlService.createTemplateFromFile(file)
            .evaluate()
 SpreadsheetApp.getUi().showModalDialog(html, 'J&T Dashboard');
}

索引.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!=include('stylesheet');?>
  </head>
  
  <body style="background-color:powderblue;">
    
    <div class="btnGroup2" style="width:100%">
      <button style="width:50%" button onclick="google.script.host.close() ; google.script.run.displayHtmlViewer('dashboard')">Open dashboard</button>
    </div>

    <div class="divider"/></div>

    <div class="btnGroup1" style="width:100%">
      <button style="width:50%">Future Button 1</button>
      <button style="width:50%">Future Button 2</button>
    </div>

    <div class="divider"/> </div>


    <div class="btnGroup1" style="width:100%">
      <button style="width:50%">Future Button 3</button>
      <button style="width:50%">Future Button 4</button>
    </div>
    <div class="divider"/> </div>


    <div class="btnGroup1" style="width:100%">
      <button style="width:50%">Future Button 5</button>
      <button style="width:50%">Future Button 6</button>
    </div>

    <div class="divider"/> </div>

    <div class="btnGroup2" style="width:100%" id=myBtn>
      <button style="width:50%" button onclick="google.script.host.close()"> Exit </button>
    </div>


  </body>
</html>

dashboard.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
 <body>
<h4>This is the Dashboard</h4>
  </body>
</html>

【问题讨论】:

    标签: html google-apps-script google-sheets


    【解决方案1】:

    在已经打开的对话框下打开对话框时,关闭现有对话框。我认为这可能可以用于您的情况。在您的脚本中,google.script.host.close() 关闭对话框。这样,google.script.run.displayHtmlViewer('dashboard') 不会运行。那么,下面的修改呢?

    发件人:

    <button style="width:50%" button onclick="google.script.host.close() ; google.script.run.displayHtmlViewer('dashboard')">Open dashboard</button>
    

    收件人:

    <button style="width:50%" button onclick="google.script.run.displayHtmlViewer('dashboard')">Open dashboard</button>
    

    【讨论】:

    • 不幸的是,这是我最初的解决方案,也无济于事,这让我觉得我在其他地方错过了一些东西。
    • @RichardGeef 感谢您的回复。我必须为我糟糕的技能和糟糕的英语水平道歉。不幸的是,来自Unfortunately, this was my original solution, also to no avail, which makes me think Im missing something somewhere else.,我无法理解您的情况。可以问一下具体情况吗?
    • 我已经尝试过使用你的回答 但它没有用。
    • @RichardGeef 感谢您的回复。我带来的不便表示歉意。从I have already tried to use your answer &lt;button style="width:50%" button onclick="google.script.run.displayHtmlViewer('dashboard')"&gt;Open dashboard&lt;/button&gt; But it did not work. 开始,当我测试您的脚本时,对话框从第一个更改为dashboard.html。所以我提出了它。如果可以,您能否提供示例电子表格,包括您的问题中的脚本以复制您的问题?借此,我想确认一下。
    • 这就是问题所在,谢谢。我使用的是 Chrome,但它不起作用。我切换到 Firefox,它确实有效。我想问题一定出在我的 Chrome 扩展程序之一上。非常感谢你的帮助。我知道解决方案很简单。
    猜你喜欢
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    相关资源
    最近更新 更多