You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Apps Script中从HTML对话框调用alert时弹窗两次的问题求助

Google Apps Script中从HTML对话框调用alert时弹窗两次的问题求助

大家好,我遇到了一个特别费解的问题,想请各位帮忙看看!我写了三个文件,实现的逻辑很简单:

  • 用户通过自定义菜单打开一个模态对话框
  • 用户点击对话框上的按钮
  • 按钮点击后调用函数,显示一个简单的alert

就这么个流程,但alert居然会弹出两次!以下是我的代码:

custom-menu.gs

function onOpen() {
  SpreadsheetApp.getUi().createMenu('custom menu')
      .addItem('button 1','someFunction')
      .addToUi();
}

gas-file.gs

function someFunction() {
  const htmlOutput = HtmlService.createHtmlOutputFromFile("html-file");
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, "Some Title");
}

function someFunc1() {
  SpreadsheetApp.getUi().alert("someFunc1() has been called.")
}

html-file.html

<!DOCTYPE html>
<html>
  <body>
    <button type="button" onclick="submit()">Submit</button>
    <script>

      function submit() {
        google.script.run.someFunc1();
      }      

    </script>
  </body>
</html>

我完全搞不明白这是怎么回事,希望能得到大家的帮助,提前谢谢各位了!

备注:内容来源于stack exchange,提问作者Ryu Hiroyama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 09:54:51