在新的Google网站中进行表单重定向 [英] Form redirecting in new google sites
问题描述
我使用应用程序脚本创建了一个表单.在html文件中,我有以下内容;
I created a form using the app script. In the html file I have the below;
<form name="Subscribe-to-Central" id="Subscribe-to-Central" action="https://script.google.com/macros/s/key/exec" method="POST" onsubmit="myFunction()">
Inputs ..
</form>
<script>
function myFunction() {
alert("Successfully subscribed. Please press okay to return to the home page");
window.open("URL", "_top");
}
</script>
表单运行良好,可以将日期发送到附件中,并在提交后也重定向到"URL",但是问题是当我尝试将表单嵌入新的Google网站时,它仍然将数据发送到工作表,但没有更多重定向,它会显示以下错误"script.googleusercontent.com拒绝连接."
The form is working good at which sending the date to the attached sheet and also redirecting to the "URL" after submit but the problem is when I tried to embed the form in the new google sites, it still sends the data to the sheet but no more redirect and it gives the following error "script.googleusercontent.com refused to connect."
PS:请注意,我仅在新的Google网站上会遇到此问题.我尝试将相同的脚本嵌入经典的Google网站中,但效果很好
PS: Please note that I face this problem only with new google sites. I tried embedding the same script in classic google sites and it worked just fine
任何帮助将不胜感激
推荐答案
答案:
不幸的是,由于与经典站点相比,新站点的工作方式发生了变化,因此不再可能在新站点中完成重定向.
从控制台中可以看到,尝试从JavaScript导航顶级窗口时,会出现以下错误:
As you can see in the console, you get the following error when attempting to navigate the top-level window from JavaScript:
不安全的JavaScript尝试从URL为
https://< id> .script.googleusercontent.com的框架开始对起源为
.试图在顶层窗口中导航的框架已沙盒化,但https://sites.google.com
的框架进行导航/userCodeAppPanelallow-top-navigation
或allow-top-navigation-by-user-activation
的标志未选中设置.
Unsafe JavaScript attempt to initiate navigation for frame with origin
https://sites.google.com
from frame with URLhttps://<id>.script.googleusercontent.com/userCodeAppPanel
. The frame attempting navigation of the top-level window is sandboxed, but the flag ofallow-top-navigation
orallow-top-navigation-by-user-activation
is not set.
和:
拒绝在框架中显示
< URL>
,因为它将X-Frame-Options
设置为sameorigin
.
可以使用 HtmlService
的 .setXFrameOptionsMode()
方法为嵌入式Google Apps脚本页面设置 X-Frame-Options
>,并使用 XFrameOptionsMode
枚举器,如下所示:
It is possible to set the X-Frame-Options
for the embedded Google Apps Script page using the .setXFrameOptionsMode()
method of HtmlService
and using the XFrameOptionsMode
Enumerator as shown here:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('index')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
不幸的是,沙盒需要 allow-top-navegation
或 allow-top-navegation-by-user
标志才能从沙盒重定向.根据hte文档, HtmlService
中唯一可用的沙盒模式是以下Enmerators:
Unfortunately, the Sandbox needs the allow-top-navegation
or allow-top-navegation-by-user
flag to be able to redirect from a Sandbox. As per hte documentation, the only Sandbox modes available from HtmlService
are the following Enmerators:
-
IFRAME
:一种沙箱模式,使用iframe沙箱而不是EMULATED
和NATIVE
模式使用的Caja沙箱技术.对于2015年11月12日之前的新脚本以及2016年7月6日之前的所有脚本,此模式均为默认模式.
IFRAME
: A sandbox mode that uses iframe sandboxing instead of the Caja sandbox technology used by theEMULATED
andNATIVE
modes. This mode is the default for new scripts as of November 12, 2015 and for all scripts as of July 6, 2016.
NATIVE
:基于ECMAScript 5严格模式构建的沙箱模式.建立在ECMAScript 5严格模式之上的沙盒模式.截至2016年7月6日,该模式为日落模式.所有脚本现在都使用IFRAME模式.
NATIVE
: A sandbox mode that is built on top of ECMAScript 5 strict mode. A sandbox mode built on top of ECMAScript 5 strict mode. This mode was sunset as of July 6, 2016. All scripts now use IFRAME mode.
EMULATED
:一种旧式沙箱模式,仅使用ECMAScript 3中提供的功能来模拟ECMAScript 5严格模式.该模式是2014年2月之前的默认模式.使用 EMULATED
现在将改为使用 IFRAME
.
EMULATED
: A legacy sandbox mode that emulates ECMAScript 5 strict mode using only the features available in ECMAScript 3. This mode was the default prior to February 2014. Actually deprecated, All scripts attempting use EMULATED
will now use IFRAME
instead.
也无法在新网站"界面中设置沙盒嵌入的标志,因此也无法从网站"端添加所需的导航允许标志.
The setting of flags for the Sandboxed embed isn't possible to do from within the New Sites interface either, so adding the required navigation allow flag can't be done from Sites end either.
只要您使用新站点",这里什么都做不成.但是,正如您已经指出的那样,如果这是一种合适的解决方法,那么经典站点确实允许这样做.
There isn't anything here that can be done as long as you are working with New Sites. As you have already pointed out, however, Classic Sites do allow this if this is a suitable workaround.
我知道这通常是个坏消息,但我希望这对您有帮助!
I know this is generally bad news, but I hope this is helpful to you!
- 同源政策-MDN Web文档
- 文档对象模型(DOM)-MDN Web文档
- Google Apps脚本-类
HtmlOutput
- 方法
HtmlOutput.setXFrameOptionsMode(mode)
- 枚举
XFrameOptionsMode 代码>
- 方法
HtmlOutput.setSandboxMode(mode)
- 枚举
SandboxMode
这篇关于在新的Google网站中进行表单重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 方法