简体   繁体   English

提交旧的 Google 表单然后重定向到另一个页面

[英]Submit Old Google Form then redirect to another page

I am utilizing a Google Form on a webpage.我在网页上使用 Google 表单。 I copied the source code from the form directly onto my page so that I can modify some of the HTML instead of using an iframe.我将表单中的源代码直接复制到我的页面上,以便我可以修改一些 HTML,而不是使用 iframe。 Then instead of taking the user to the google docs response page I would like to redirect them to another page.然后,我想将用户重定向到另一个页面,而不是将用户带到 google docs 响应页面。

The trouble that I am running into is with the page redirect.我遇到的问题是页面重定向。 I was able to get this working properly in Chrome and Firefox with this:我能够通过以下方式在 Chrome 和 Firefox 中正常工作:

<form target="GoogleResponse" action="https://docs.google.com/spreadsheet/
formResponse?formkey=xxxxxxxxxxxxxxxxxxxxxxxxxx&amp;ifq;" onsubmit="
window.location = 'targetPage.html';" method="POST" id="ss-form">

IE and Safari both did the redirect automatically and the response never got written to the Google Form. IE 和 Safari 都自动执行重定向,并且响应从未写入 Google 表单。 If I drop the redirect, the action works perfectly in both and the response is recorded in the Google spreadsheet.如果我放弃重定向,该操作在两者中都能完美运行,并且响应会记录在 Google 电子表格中。

So I attempted to pull the action out and instead did it everything in onsubmit instead, like so:因此,我尝试将操作拉出,而是在 onsubmit 中执行所有操作,如下所示:

<form target="GoogleResponse" onsubmit="this.action = https://docs.google.com
/spreadsheet/formResponse?formkey=xxxxxxxxxxxxxxxxxxxxxxxxxx&amp;ifq'; 
window.location = 'targetPage.html';" method="POST" id="ss-form">

Same problem as before, IE and Safari both redirect, and nothing is written to the Google spreadsheet.和以前一样的问题,IE 和 Safari 都重定向,并且没有任何内容写入 Google 电子表格。 And once again, if I remove the redirect the response gets recorded in all browsers.再一次,如果我删除重定向,响应将记录在所有浏览器中。 I can also do other stuff like throw in an alert after the action, and everything continues to work fine.我还可以做其他事情,比如在行动后发出警报,一切都继续正常工作。 The only time I see the issue is with the redirect.我唯一一次看到问题是重定向。

So at this point the only thing I can figure is that their is some sort of conflict between the redirect and the action.所以在这一点上,我唯一能想到的是它们是重定向和动作之间的某种冲突。 I have pretty limited working knowledge of javascript and forms so any help or recommendations would be greatly appreciated!我对 javascript 和表单的工作知识非常有限,因此将不胜感激任何帮助或建议!

Sounds like the browsers have not complete the form submission before handling the redirect.听起来浏览器在处理重定向之前还没有完成表单提交。 onsubmit happens before the submission itself so you can not handle the issue there. onsubmit 发生在提交本身之前,因此您无法在那里处理问题。

Use the onload function of the target iframe for the redirect.使用目标 iframe 的 onload 函数进行重定向。

This has been asked in similar manner:这已经以类似的方式被问到:

Old Google Form redirect after submission提交后旧的 Google 表单重定向

Take a good look at the answer.好好看看答案。 The onload function of the iframe will handle the redirect, so the redirect will not happen until the submission is complete and a response has been given from google. iframe 的 onload 函数将处理重定向,因此在提交完成并且 google 给出响应之前不会发生重定向。 So when the hidden response from google is loaded we fire a redirect.因此,当加载来自 google 的隐藏响应时,我们会触发重定向。 This is async functionality between the client and server.这是客户端和服务器之间的异步功能。 We are waiting for the server to handle the data before redirecting.我们在重定向之前等待服务器处理数据。


Extended note: You could try putting the redirect within a setTimeout function.扩展说明:您可以尝试将重定向放在 setTimeout 函数中。 This would delay the execution of the redirect, allowing the server to handle the submission first.这将延迟重定向的执行,允许服务器首先处理提交。 But setTimeout requires a fixed amount of time, so if the data handling is not synchronous (ie. asynchronous) setTimeout will not work as it may fire to early or too late.但是 setTimeout 需要固定的时间量,因此如果数据处理不是同步(即异步)setTimeout 将不起作用,因为它可能会触发得太早或太晚。 Asynchronous data handling applies when the data processing requires an undetermined amount of time (such as http requests).异步数据处理适用于数据处理需要不确定的时间(例如 http 请求)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM