javascript - 在运行时使用 GAS 调整 HTML 模态的大小

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

我有一个显示 html 表单的模式。该表格有一个按钮。 模态最初设置为 600x425 的宽度。然后在运行时,如果按下按钮,它应该将模式大小从 600x425 调整为 300x200。

如何使用 Google Apps 脚本获取此内容

function showPickerImages() {

        var html = HtmlService
            .createTemplateFromFile("MyHTMLForm")
            .evaluate()
            .addMetaTag("viewport", "width=device-width, initial-scale=1")
            .setWidth(600)
            .setHeight(425)
            .setTitle("Resize demo")
            .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
        SpreadsheetApp.getUi().showModalDialog(html, 'demo');
}

MyHTMLForm.html

<button onclick="resizeModalDialog()"></button>

enter image description here

最佳答案

使用google.script.host.setWidth(width)setHeight :

// resize modal window
function resizeModalDialog()
{
  google.script.host.setWidth(300);
  google.script.host.setHeight(200);
}

关于javascript - 在运行时使用 GAS 调整 HTML 模态的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47471447/

相关文章:

javascript - 目前哪些浏览器支持 Web Worker?

javascript - 如何添加固定导航栏切换动画

javascript - 如何将重复的单元格与谷歌应用程序脚本合并在一起?

google-apps-script - 如何使用 Drive Rest API 读取云端硬盘照片

javascript - jQuery live 不工作

javascript - 向包含相同类的每个 div 添加新 id

javascript - 从 iframe 调用后菜单无法正确显示

javascript - 同步独立的电子表格行,由 IMPORTRANGE() 填充

javascript - 尚未找到函数 SubmitSurvey 的定义,但我定义了它

javascript - 在 then block 中使用类函数