问题
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:
回答1:
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.
来源:https://stackoverflow.com/questions/60597363/open-a-url-on-form-submit-event-google-app-script