0

I'm just learning google script and want to start by making a simple hello world. I have done google's tutorial and when I click "test this code" on the publish web app popup, the code runs and I get my basic hello world result. Great. But When I paste the provided URL into the browser or embed that same URL into google sites, I just get a blank page.

How do I run an web app? Am I missing something?

code.gs:

function doGet() {
      var html= HtmlService
          .createTemplateFromFile('Index');
          html.name = 'David';         
          return html.evaluate();
    }  

index.html:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>Hi <?=name?>!</b>
  </body>
</html>

Coming from a basic PHP background, I'm used to just going to the URL of the .php file and bang, away it goes... I'm so confused.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335

2 Answers2

0

https://stackoverflow.com/a/40843413/6288442

Google had just recently enabled this feature. It has been under a 'feature request' status for quite a long time. Link here

You can now explicitly define X-Frame-Options.

To allow embedding under another domain, the option should be HtmlService.XFrameOptionsMode.ALLOWALL

Google documentation on the subject:

https://developers.google.com/apps-script/reference/html/html-output#setXFrameOptionsMode(XFrameOptionsMode)

Example:

function doGet() { return HtmlService.createTemplateFromFile('form.html') .evaluate() // evaluate MUST come before setting the Sandbox mode .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); }

Hope this helps!

C. Geek
  • 347
  • 2
  • 16
0

I think this should work

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>Hi <?!=name?></b>
  </body>
</html>

https://developers.google.com/apps-script/guides/html/templates#force-printing_scriptlets

Name of file should also be exactly same I think Index and index won't work

Umair Mohammad
  • 4,489
  • 2
  • 20
  • 34