Apps 脚本拒绝连接
Apps Script Refused to Connect
我正在尝试学习 Apps 脚本和一些前端 Web 开发人员。我在 Apps 脚本中写了一些代码,我试图在 Google 站点中呈现它。
这是我在 Apps 脚本中使用的 doGet 函数:
function doGet() {
var template = HtmlService.createTemplateFromFile('Index');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
有趣的是,当我使用 Google-given URL 时,脚本会自行呈现:
https://sites.google.com/corp/view/vrajlinkshortener
但是,当我输入自定义域时,情况并非如此:
www.wharton.ml
我查看了文档,但仍然无法弄清楚为什么自定义域会禁止 Apps 脚本表单工作。
有什么建议吗?谢谢!
您需要将选项 XFrameOptionsMode
设置为 ALLOWALL
。
XFrameOptionsMode
https://developers.google.com/apps-script/reference/html/x-frame-options-mode
Setting XFrameOptionsMode.ALLOWALL will let any site iframe the page, so the developer should implement their own protection against clickjacking.
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
如以下评论所述( 说)检查您的浏览器是否仅登录到一个 Google 帐户。
只要在下面添加,就可以了
函数 doGet(e){
var temp = HtmlService.createTemplateFromFile('html')
return temp.evaluate().setTitle("预订Window").setSandboxMode(HtmlService.SandboxMode.IFRAME).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
我正在尝试学习 Apps 脚本和一些前端 Web 开发人员。我在 Apps 脚本中写了一些代码,我试图在 Google 站点中呈现它。
这是我在 Apps 脚本中使用的 doGet 函数:
function doGet() {
var template = HtmlService.createTemplateFromFile('Index');
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
有趣的是,当我使用 Google-given URL 时,脚本会自行呈现: https://sites.google.com/corp/view/vrajlinkshortener
但是,当我输入自定义域时,情况并非如此: www.wharton.ml
我查看了文档,但仍然无法弄清楚为什么自定义域会禁止 Apps 脚本表单工作。
有什么建议吗?谢谢!
您需要将选项 XFrameOptionsMode
设置为 ALLOWALL
。
XFrameOptionsMode
https://developers.google.com/apps-script/reference/html/x-frame-options-mode
Setting XFrameOptionsMode.ALLOWALL will let any site iframe the page, so the developer should implement their own protection against clickjacking.
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
如以下评论所述(
只要在下面添加,就可以了
函数 doGet(e){ var temp = HtmlService.createTemplateFromFile('html') return temp.evaluate().setTitle("预订Window").setSandboxMode(HtmlService.SandboxMode.IFRAME).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) }