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