在 iFrame 中嵌入 Google Apps 脚本 [英] Embedding Google Apps Script in an iFrame
问题描述
我正在尝试将使用 Google Apps Script 中的 Javascript 动态构建的页面嵌入到 iFrame 中的我的网站中,但未显示 iFrame 的内容.Google Apps 脚本具有阻止加载的同源策略.
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>
我得到的错误是:
Refused to display 'https://script.google.com/a/macros/SCRIPT_ID'
in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
有没有办法改变策略并在 iFrame 中加载内容?
Is there a way to alter the policy and load the content in an iFrame?
推荐答案
Google 最近刚刚启用了此功能.很长一段时间以来,它一直处于功能请求"状态.此处链接
Google had just recently enabled this feature. It has been under a 'feature request' status for quite a long time. Link here
您现在可以明确定义 X-Frame-Options.
You can now explicitly define X-Frame-Options.
要允许嵌入到另一个域下,选项应该是 HtmlService.XFrameOptionsMode.ALLOWALL
To allow embedding under another domain, the option should be HtmlService.XFrameOptionsMode.ALLOWALL
有关该主题的 Google 文档:
Google documentation on the subject:
示例:
function doGet() {
return HtmlService.createTemplateFromFile('form.html')
.evaluate() // evaluate MUST come before setting the Sandbox mode
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
希望这有帮助!
这篇关于在 iFrame 中嵌入 Google Apps 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!