Unable to get links working in Google Apps Script

2019-04-12 02:42发布

In Google Apps Script, the code below works for me in the default sandbox mode, but when I change the sandbox mode to IFRAME, the code does not work. In IE11, I get a blank page after clicking on the first button. In Chrome, the first button works but clicking the subsequent button brings up a blank page.

The code below was taken from this post

Code.gs

/**
 * Get the URL for the Google Apps Script running as a WebApp.
 */
function getScriptUrl() {
 var url = ScriptApp.getService().getUrl();
 return url;
}

/**
 * Get "home page", or a requested page.
 * Expects a 'page' parameter in querystring.
 *
 * @param {event} e Event passed to doGet, with querystring
 * @returns {String/html} Html to be served
 */
function doGet(e) {
  Logger.log( Utilities.jsonStringify(e) );
  if (!e.parameter.page) {
    // When no specific page requested, return "home page"
    return HtmlService.createTemplateFromFile('my1').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
  }
  // else, use page parameter to pick an html file from the script
  return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

my1.html

<html>
  <body>
    <h1>Source = my1.html</h1>
    <?var url = getScriptUrl();?><a href='<?=url?>?page=my2'> <input type='button' name='button' value='my2.html'></a>
  </body>
</html>

my2.html

<html>
  <body>
    <h1>Source = my2.html</h1>
    <?var url = getScriptUrl();?><a href='<?=url?>?page=my1'> <input type='button' name='button' value='my1.html'></a>
  </body>
</html>

2条回答
beautiful°
2楼-- · 2019-04-12 03:20

target="_blank" inside the anchor tag ?

查看更多
聊天终结者
3楼-- · 2019-04-12 03:33

Apps Script now only supports IFRAME mode. NATIVE support is gone. See here

查看更多
登录 后发表回答