如何在Google电子表格中获取包含html和“是/否"按钮的警报消息,该消息将停止执行脚本,直到用户单击“是"或“否"? [英] How to get an alert message containing html and a yes/no-button in google spreadsheet that stops executing the script till user has clicked yes or no?

查看:240
本文介绍了如何在Google电子表格中获取包含html和“是/否"按钮的警报消息,该消息将停止执行脚本,直到用户单击“是"或“否"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Google电子表格发送html电子邮件,对于某个组,我想先查看预览然后再发送.通过单击电子表格上的菜单项可以调用发送电子邮件的脚本.因此,我想创建一个包含html消息和一个发送是或否电子邮件的按钮的弹出窗口.多封电子邮件就是这种情况,因此脚本必须等待用户输入后才能显示下一封电子邮件.

I'm sending html emails from a google spreadsheet, and for a certain group, I want to first see a preview before sending it. The script to send the emails can be invoked by clicking a menu item on the spreadsheet. So I want to create a pop-up that contains the html message and a button to send the email yes or no. This is the case for multiple emails, so the script has to wait for user input before showing the next email.

我可以使用Ui类的警报功能,问题在于它仅接受消息的字符串,而不接受html.但是警报不会停止执行代码,直到用户输入为止.

I can use the alert function from the Ui-class, problem is that it only accepts a string for the message, not html. But the alert does stop code execution till the user gives input.

另一个选项是Ui类的showModelDialog函数,在这里我可以给html作为参数,但是google-apps-script不会停止执行,因此结果是我只会看到最后一封电子邮件.

The other option is showModelDialog function from the Ui-class, here I can give html as a parameter, but the google-apps-script does not stop executing, so the result is that I will only see the pop-up for the last email.

警报功能不是一个选项,因为我不能将html作为参数,因此showModelDialog是最佳选择.我使用showModelDialog发现的可能不太好用的解决方案是在每个弹出窗口之间使用类实用程序中的sleep函数,或者每次调用该函数时仅发送一封电子邮件.

The alert function is not an option because I can't give html as a parameter, so showModelDialog is the best choice. Possible not-so-pretty-solutions that I found using showModelDialog, are using the sleep function from the class Utilities between each pop-up or only sending one email each time the function is invoked.

有没有一种解决方案,我可以显示带有html电子邮件的弹出窗口,并且应用程序脚本会停止执行,直到它接收到来自用户的输入为止.

Is there a solution where I can show a pop-up with the html email and the apps script stops executing till it receives input from the user?

推荐答案

可以使用showModelDialog本身来实现.
您可以将发送邮件的功能放在 sendMail 中.

It can be accomplished with showModelDialog itself.
You can put the function to send the mail in a function say sendMail.

现在添加一个按钮,以在onclick事件上调用该函数.

Now add a button to call that function on onclick event.

<input id="btn" type="button" value="Send" onclick="google.script.host.close()" />

有关更多信息,请参见
Google Apps脚本中的自定义对话框
google.script.run类(客户端API)

For more info refer
Custom Dialogs in Google Apps Script
Class google.script.run (Client-side API)

这篇关于如何在Google电子表格中获取包含html和“是/否"按钮的警报消息,该消息将停止执行脚本,直到用户单击“是"或“否"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆