Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda