在表单提交事件上打开 URL - Google 应用程序脚本

Open a URL on Form Submit Event - Google App Script

我使用的是 Serge insas 在此处提供的示例代码: Google Apps Script to open a URL

我稍微修改了代码,如下所示:

Code.GS

   function modalUrl(){
      FormApp.getUi()
       .showModalDialog(
         HtmlService.createHtmlOutputFromFile('openUrl').setHeight(50),
         'Opening Whosebug'
       )
    } 

openURL.html

<!DOCTYPE html>
<html>
  <head>
   <base target="_blank">
    <script>
     var url1 ='
     var winRef = window.open(url1);
     winRef ? google.script.host.close() : window.alert('Allow popup to redirect you to '+url1) ;
     window.onload=function(){document.getElementById('url').href = url1;}
    </script>
  </head>
  <body>
    Kindly allow pop ups</br>
    Or <a id='url'>Click here </a>to continue!!!
  </body>
</html>

出现的问题是在提交表单后无法访问 FormApp.getUi。 请参阅以下错误:

如有关 UI class 的文档中所述:

A script can only interact with the UI for the current instance of an open editor, and only if the script is container-bound to the editor.

在 Google 表单的情况下,编辑器是在您编辑特定表单时而不是在您填写表单时。如果表单未嵌入网站,则无法在表单提交后自动重定向用户,此支持中的解决方法可能对您有所帮助。article