0

First of all I am sorry if I use GAS tools incorrectly.

Context :

I need to generate a simple webapp including link that will be framed in a google-site.

target="_self" and .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) are ensential for this reason. I cannot set target on any other values than _self, (I'm aware that the following code wok perfectly with _top)

see this previous question : Can't have link in Embedded web app in Google site?

Code :

Use this simple code sample deployed as an Web app :

function doGet(e) {
  var count = Number(e.parameters.count) || 0
  var html = "<a target='_self' href='https://script.google.com/macros/s/";
    html += ScriptApp.getService().getUrl().substr(35); //the id of the script
    html += "?count="+ (count+1) + "'>click me twice</a><br>" + count;
  return HtmlService.createHtmlOutput(html).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

It just insert a link to the curent page, counting in the get how many times the link is clicked.

Issues :

  • First you can see that the code dont work in the "latest code" preview (url ending by /dev). setXFrameOptionsMode dont seem to work on preview. We cant test it their but we can still deploy it so that's ok.

error on lasted code mode

  • Once published (url ending by /exec) the web app seem to work correctly at first sight but you can click on the link only once.
Marios
  • 26,333
  • 8
  • 32
  • 52
Julien Maret
  • 579
  • 1
  • 4
  • 22
  • What do you mean by `the code dont work in the "latest code" preview`? What behaviour does it exhibit? – Rafa Guillermo Jun 05 '20 at 13:37
  • `setXFrameOptionsMode` dont seem to be supported. So when you click a link you just get "script.google.com dont allowthe connexion". Just like if you dont set it on `ALLOWALL` – Julien Maret Jun 05 '20 at 13:55
  • @RafaGuillermo i putted a screen – Julien Maret Jun 05 '20 at 14:00
  • 1
    You need to understand how your frames are nested. `_self` isn't *.google.com, but *.googleusercontent.com. See [tag info page](https://stackoverflow.com/tags/google-apps-script-web-application/info) for more details. Workaround is to use [`window.postMessage`](https://stackoverflow.com/questions/56400233/issue-with-embedding-google-apps-script-in-an-iframe/56400626?r=ggh), but I'm not sure whether sites.google.com would mess with receivers. – TheMaster Jun 05 '20 at 17:09
  • Thank for the link. I was desesperate to find a thread about it. Now I'm home i can access to navigator dev tool i understand it a bit better too. I look ta this – Julien Maret Jun 05 '20 at 20:19
  • Ok I get how it is done. But i have no way to change the top level frame. I cant really implement anycode on a google site, it's just "user friendly" site creator. So i can't handle message. – Julien Maret Jun 08 '20 at 12:02

0 Answers0