在表单提交事件上打开URL-Google App脚本 [英] Open a URL on Form Submit Event - Google App Script

查看:45
本文介绍了在表单提交事件上打开URL-Google App脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Serge insas提供的示例代码,可在以下位置找到:

解决方案

如有关 UI 类:

脚本只能与用户界面的当前实例的用户界面进行交互打开编辑器,并且前提是脚本是容器绑定到编辑器的.

对于Google表单,编辑器是在您编辑特定表单时而不是在填写表单时.如果表单未嵌入网站中,则无法在提交表单后自动重定向用户,这可能是此支持中的解决方法文章可以为您提供帮助.

I am using the sample code provided by Serge insas found here: Google Apps Script to open a URL

I have modified the code slightly as seen below:

Code.GS

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

openURL.html

<!DOCTYPE html>
<html>
  <head>
   <base target="_blank">
    <script>
     var url1 ='https://stackoverflow.com/a/54675103';
     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>

The issue is appears is that it is not possible to access FormApp.getUi after a form has been submitted. See the error below:

解决方案

As stated in the documentation regarding 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.

In the case of a Google Form, the editor is when you're editing a specific form and not when you're filling one. You can't automatically redirect a user after a form submission if the form is not embedded in a website, may be the workaround in this support article can help you.

这篇关于在表单提交事件上打开URL-Google App脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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