Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Google Apps Script: HtmlService.createHtmlOutput not working in iframe
  • Create a blank google docs file
  • Add the following apps script:
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');
}

Now these 2 menu entries appear:

enter image description here

"Open dialog" works:

enter image description here

"Open html" works:

enter image description here

Embed the google docs file in an iframe:

<iframe
   src="https://docs.google.com/document/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/edit"
></iframe>

"Open dialog" works:

enter image description here

"Open html" does not work:

enter image description here

Error message in console:

enter image description here

I thought this is exactly what this line does:

output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

What am I missing?

Here is a link to reproduce that problem:

  • Google Docs with Apps Script
  • Iframe Embed example
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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:

function onOpen(e)
{
    DocumentApp.getUi().createAddonMenu().addItem('Open dialog', 'openDialog').addItem('Open html', 'openHtml').addToUi();
}
function openDialog() {
    DocumentApp.getUi().alert('This works');
}
function openHtml() {
    var output = HtmlService.createHtmlOutputFromFile('test.html'); //use createHtmlOutputFromFile instead
    output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
    DocumentApp.getUi().showModalDialog(output, 'Title');
}

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".

Files List

Output

iframe

Reference

  • Class HtmlService/createHtmlOutputFromFile(filename)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!