关闭Htmlservice弹出窗口 [英] Close Htmlservice popup

查看:96
本文介绍了关闭Htmlservice弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当在Google表单上点击提交"按钮时是否可以关闭htmlservice弹出窗口

I am wondering if is possible to close the htmlservice popup when the submit button is hit on the Google form

function launchForm() {
  var form = FormApp.openById('15Qw9jmolybvMbx2d3UhddEWHrKe0zBiV5_asKXolsM0');
  var formUrl = form.getPublishedUrl(); 

//  var response = UrlFetchApp.fetch(formUrl);
//  var formHtml = response.getContentText();

  var htmlApp = HtmlService
      .createHtmlOutput('<h1>Your Organization</h1>')
      .append('<iframe src ="' + formUrl + '?embedded=true" width="1000" height="900" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>')
      .setTitle('Form')
      .setWidth(1000) 
      .setHeight(1000);

  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}

我希望当我点击表单上的提交"按钮时,html应用程序将关闭

I'm hoping that when I hit the submit button on the form, the html app will close

推荐答案

Google表单在表单导航或提交时加载每个页面.您可以收听这些事件,计算页面加载数量并关闭弹出窗口.

Google forms load each page on form navigation or submit. You can listen to those events, count the number of page loads and close the pop up.

function showGoogleForm() {
  var form = FormApp.openById(/*FORM EDIT ID*/);
  var formUrl = form.getPublishedUrl();
  var temp = HtmlService.createTemplateFromFile('googleForm');
  temp.pubUrl = formUrl;
  var htmlApp = temp
    .evaluate()
    .setTitle('Form')
    .setWidth(1000)
    .setHeight(1000);
  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}

googleForm.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <script type="text/javascript">
      var i = 0;
      var totalSections = 1; //TODO Set Total number of pages in your form
      check = () => {
        if (++i > totalSections) {
          alert('Thank You for filling up the form');
          setTimeout(google.script.host.close, 7);
        }
      };
    </script>
  </head>
  <body>
    <h1>
      MASTER FORM
    </h1>
    <iframe
      onload="check()"
      referrerpolicy="no-referrer"
      sandbox="allow-scripts allow-forms"
      src="<?=pubUrl?>?embedded=true"
      width="700"
      height="520"
      frameborder="0"
      marginheight="0"
      marginwidth="0"
    ></iframe>
  </body>
</html>

这篇关于关闭Htmlservice弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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