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
相关产品推荐
相关产品推荐

