Student
Student

Reputation: 89

Apps Script Refused to Connect

I am trying to learn Apps Script and some fron-end web dev. I wrote some some code in Apps Script and I am trying to render it in a Google Site.

Here is the doGet function that I use in my Apps Script:

function doGet() {
  var template = HtmlService.createTemplateFromFile('Index');
  return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

Interestingly, the script renders itself when I use the Google-given URL: https://sites.google.com/corp/view/vrajlinkshortener

However, that is not the case when I enter the custom domain: www.wharton.ml

I checked the documentation and I still could not figure out why a custom domain would prohibit Apps Script form working.

Any tips? Thanks!

Upvotes: 1

Views: 10471

Answers (2)

rpmathur 12
rpmathur 12

Reputation: 55

Just add below, it is working

function doGet(e){
  var temp = HtmlService.createTemplateFromFile('html')
  return temp.evaluate().setTitle("Booking Window").setSandboxMode(HtmlService.SandboxMode.IFRAME).setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}

Upvotes: -2

oshliaer
oshliaer

Reputation: 4979

You need to set the option XFrameOptionsMode to ALLOWALL.

XFrameOptionsMode

https://developers.google.com/apps-script/reference/html/x-frame-options-mode

Setting XFrameOptionsMode.ALLOWALL will let any site iframe the page, so the developer should implement their own protection against clickjacking.

return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);

As stated in the comments below (Shan Eapen Koshy said) check that your browser is logged into one Google account only.

Upvotes: 8

Related Questions