0

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: enter image description here

New_2_Code
  • 330
  • 2
  • 18

1 Answers1

2

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.

Andres Duarte
  • 3,166
  • 1
  • 7
  • 14