3

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>
  • Do you need `IFRAME` for something else? If not, just use `NATIVE`. If you want a SPA (Single Page Application) that only loads the URL once, and navigates to other pages, you can "sort of" do that as long as you serve all the CSS up front. If you are interested in how to get HTML content as needed, so it's not all loaded up front, there is a way to do that. – Alan Wells Feb 07 '15 at 18:45
  • Are you trying to achieve "Deep Linking"? The ability to share a link to a specific page in the application, and have the application go directly to that page. – Alan Wells Feb 07 '15 at 18:50
  • I wanted to use IFRAME because I have a dark background, but in NATIVE mode, there is a white gap at the top and sometimes at the bottom of the screen. Regarding deep linking, yes, I want to do that and also have a lot of intra-linking where one page links to another. – Greg Atkinson Feb 08 '15 at 00:25

2 Answers2

0

target="_blank" inside the anchor tag ?

Bryan P
  • 5,031
  • 3
  • 30
  • 44
  • I tried a few different "target" attributes, none of which quite worked for me. ### results of my experiments ### target="_blank" - In IE 11 and Chrome, it works but it opens a new window each time target="_parent" or target="_top" - In IE 11, nothing happens when you click the button - In Chrome, it works but it opens a new window each time target="_self" - In IE 11 and Chrome, it behaves the same as not having a target attribute target="test" - In IE 11, nothing happens when you click the button - In Chrome, it works but it opens a new window each time` – Greg Atkinson Feb 08 '15 at 00:17
0

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