Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda