Google Apps脚本:htmlservice.createhtmloutput在iframe中不起作用
- 创建一个空白的Google文档文件
- 添加以下应用程序脚本:
function onOpen(e)
{
DocumentApp.getUi().createAddonMenu().addItem('Open dialog', 'openDialog').addItem('Open html', 'openHtml').addToUi();
}
function openDialog() {
DocumentApp.getUi().alert('This works');
}
function openHtml() {
let output = HtmlService.createHtmlOutput('<b>This works</b>');
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
DocumentApp.getUi().showModalDialog(output, 'Title');
}
现在出现这两个菜单条目:
”打开对话框
。 png“ rel =” nofollow noreferrer“>
“ open html” works:
将Google Docs文件嵌入iframe:
<iframe
src="https://docs.google.com/document/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/edit"
></iframe>
“打开对话框”工作:
“ open html”不起作用:
console中的错误消息:
< console:<<< a href =“ https://i.sstatic.net/qyc38.png” rel =“ nofollow noreferrer”>
我认为这正是这一行:
output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
我缺少什么?
这是重现该问题的链接:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用createHtmloutputfromfile('filename')而不是
基于您的设置,我发现您只需要使用createHtmloutputfromfile()将HTML脚本链接到Google Apps脚本。对于测试用例,我使用了以下脚本:
另一方面,我使用了您在示例中使用的HTML。
要将您的HTML添加到Google Apps脚本项目中,只需单击“文件”以外的加号。在此测试案例中,我以文件名“ test.html”保存了您的HTML。
输出
参考
Use createHtmlOutputFromFile('filename') Instead
Based on your setup, I found that you just need to link your html script to your google apps script using createHtmlOutputFromFile(). For my test case, I used the following script:
On the other hand, I used the same html that you used in your example.
To add your html to the google apps script project, just click on the plus symbol besides "Files". In this test case, I saved your html under the file name "test.html".
Output
Reference