on在应用程序中提交嵌入在新谷歌网站的脚本突然出现问题



嵌入在新谷歌网站中的谷歌应用脚本直到最近才运行良好。 在我的代码中,doGet 方法用于加载表单(工作正常)。

单击"提交"按钮后,handleFormSubmit功能用于保存数据(也可以正常工作),然后表单应该重定向到确认页面(谢谢.html),这就是问题所在。

当我将脚本作为独立的 webApp 进行测试时,此确认页面会打开,但当脚本嵌入到 google 网站中时已停止打开。因此,当我单击"提交"时,所有数据都按预期保存,但"谢谢.html没有打开。

我将脚本作为独立的WebApp运行,它工作正常。所以,我真的无能为力。我想知道 Google 协作平台最近是否进行了任何更改,这些更改可能会使我的代码的某些部分不兼容?

*Index.html*
<form id="keyForm" onsubmit="handleFormSubmit(this)" action="<?= action ?>" method="post"> 

*doGet*
function doGet(e){ 
var html= HtmlService.createTemplateFromFile('index')
html.action = ScriptApp.getService().getUrl();
return html.evaluate;
}

*doPost*
function doPost(e) {
var html= HtmlService.createTemplateFromFile('Thanks.html');
html.name = e.parameter.name;
return html.evaluate;
}

index.html 包含表单的模板,该模板正在正确加载。 "action"是索引中的一个变量.html在doGet函数中设置。

表单加载后,有一个提交按钮并单击此按钮,数据应该被保存(工作正常)并且应该打开一个新页面.html谢谢(如果代码嵌入在谷歌网站中,则不起作用)。

我向您推荐以下解决方案:

与其将 Google 表单直接粘贴到您的 Google 协作平台网站中,不如嵌入 HTML 代码块。

此 HTML 脚本应通过其网址调用您的 Google 表单并将其嵌入到 Iframe 中。您可以在<script>onload部分指定提交时应该发生什么 - 例如打开您的"谢谢"页面 - 通过其URL访问。

下面是一个示例代码段:

<iframe id="gform" src="URL of your Google Form" width="SPECIFY" height="SPECIFY" frameborder="0" marginheight="0" marginwidth="0" style="margin:0 auto; max-width:100%;">Loading…</iframe>
<script type="text/javascript">
var load = 0;
document.getElementById('gform').onload = function(){
/*Execute on every reload on iFrame*/
load++;
if(load > 1){
/*Second reload is a submit*/
document.location = "URL OF YOUR THANK YOU PAGE";
}
}
</script>

最新更新