从谷歌应用脚本 html 模板呈现 html

render html from Google apps script html template

本文关键字:html 应用 脚本 谷歌      更新时间:2023-09-26

我正在使用基于 html 模板的 Google 应用程序脚本开发独立的 Web 应用程序。该应用程序的目的是一个简单的gmail,但带有自定义过滤器。 我已经完成了该过滤器并显示电子邮件列表,但遇到了呈现消息的html正文的问题。

下面是代码的一部分:

网页模板:

<table id="myTable">
</table>
<script>
...
             for (var i = 0; i < threads.length; i++)
             {
             var row = table.insertRow(0);
             row.setAttribute("messageId", threads[i].id);
             row.onclick = (function() {
             google.script.run.openMessage(this.getAttribute("messageId"));
             });
             var cell1 = row.insertCell(0);
             cell1.innerHTML = threads[i].subject;
             }
...
</script>

谷歌脚本:

function doGet() {
  return HtmlService
      .createTemplateFromFile('index')
      .evaluate().setSandboxMode(HtmlServi‌​ce.SandboxMode.NATIVE);
}
...
function openMessage(id)
{
var message = GmailApp.getMessageById(id);
var body = HtmlService.createHtmlOutput(message.getBody());
}
...

问题是:点击时显示邮件正文的最佳方式是什么?当我尝试在新窗口中打开它时 ( window.open()... )b 它会出现错误,模式窗口也无法从 html 模板中工作。提前感谢任何帮助!

我终于找到了问题的答案,它是 - jquery 对话框。

<div id="dialog"></div>
function openDialog(html) {
    $("#dialog-confirm").html(html);
    $("#dialog-confirm").dialog({
        resizable: true,
        modal: true,
        title: "Message",
        height: 500,
        width: 500,
    });
}