将Google Apps脚本嵌入到iFrame中 [英] Embedding Google Apps Script in an iFrame
问题描述
我试图将一个在Google Apps脚本中使用JavaScript动态构建的页面嵌入iFrame的网站中,但iFrame的内容未显示。 Google Apps脚本具有防止加载的同源策略。
我试图做的是(我删除了完整的链接):
< iframe src =https://script.google.com/a/macros/SCRIPT_ID>< / iframe>
我得到的错误是:
拒绝在框架中显示'https://script.google.com/a/macros/SCRIPT_ID'
,因为它将'X-Frame-Options'设置为'SAMEORIGIN 。
有没有办法改变策略并在iFrame中加载内容?
Google刚刚启用了此功能。相当长时间以来,它一直处于功能要求状态。 此处链接
您现在可以显式定义X-Frame-Options。
要允许嵌入到另一个域中,该选项应该为HtmlService.XFrameOptionsMode .ALLOWALL
有关此主题的Google文档:
https://developers.google.com/apps-script/reference/html/html-output#setXFrameOptionsMode(例如:
函数doGet(XFrameOptionsMode)
){
return HtmlService.createTemplateFromFile('form.html')
.evaluate()//在设置Sandbox模式之前,必须先进行评估
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
希望这有助于您!
I am trying to embed a page that is dynamically built using Javascript in Google Apps Script into my website in an iFrame, but the iFrame's content isn't shown. Google Apps Script has a same-origin policy which prevents it from loading.
What I am trying to do is (I removed the full link):
<iframe src="https://script.google.com/a/macros/SCRIPT_ID"></iframe>
The error I am getting is:
Refused to display 'https://script.google.com/a/macros/SCRIPT_ID'
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
Is there a way to alter the policy and load the content in an iFrame?
Google had just recently enabled this feature. It has been under a 'feature request' status for quite a long time. Link here
You can now explicitly define X-Frame-Options.
To allow embedding under another domain, the option should be HtmlService.XFrameOptionsMode.ALLOWALL
Google documentation on the subject:
Example:
function doGet() {
return HtmlService.createTemplateFromFile('form.html')
.evaluate() // evaluate MUST come before setting the Sandbox mode
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
Hope this helps!
这篇关于将Google Apps脚本嵌入到iFrame中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!