0
votes

I followed the answer in this thread Linking to another HTML page in Google Apps Script however I can only view the first page when the button is clicked and anything after that just comes up with a blank page. I have tried setting the sandbox mode to IFRAME and NATIVE detailed here Linking to another html page in google apps script does not seem to work with no luck.

Thanks for the responses, I have included my amended code below. Following this https://developers.google.com/apps-script/migration/iframe I added target="_top" to the header sections to overdide each links target attribute. I have also included the DOCTYPE html tags.

The first "index" page will now load, however clicking on a link from this page brings up an error No HTML file named project was found. (line 11, file "Code", project "Teams"). The URL plus query string looks like this

https://script.google.com/macros/s/<SCRIPTURL>/exec?page=project

Code.gs

function getScriptUrl() {
 var url = ScriptApp.getService().getUrl();
 return url;
}


function doGet(e) {
  if (!e.parameter.page) {
    return HtmlService.createTemplateFromFile('index').evaluate();
  }
  return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate();
}
index.html

<!DOCTYPE html>
<html>
  <head>
  <base target="_top">
  </head>
  <body>
    <h1>Source = index.html</h1>
    <?var url = getScriptUrl();?><a href='<?=url?>?page=project'> <input type='button' name='button' value='project.html'></a>
  </body>
</html>

project.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <h1>Source = project.html</h1>
    <?var url = getScriptUrl();?><a href='<?=url?>?page=index' target="_top"> <input type='button' name='button' value='index.html'></a>
  </body>
</html>
1
Welcome to Stack Overflow, can you share some code? And here is more on how to ask a good question (:ocordova
NATIVE mode is deprecated. The only mode available is IFRAME. If you are not familiar with console.log() and Logger.log() and the troubleshooting guide, you will need to use both of those to find problems in your code. Link to Apps Script troubleshooting guide From the information you have given, we would need to copy all the code from that answer, add it to our own project, run it, debug it, and guess at what the problem might be. Even though you have referenced code you are using, the smallest detail could be a problem.Alan Wells

1 Answers

0
votes

No HTML file named project was found. (line 11, file "Code", project "Teams")

Means the script is not finding the HTML file named project.

At this line:

return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate();

The script if looking for a HTML file named exactly as the value of parameter page, take into account this is case sensitive.

Make sure:

  • Your HTML file is named project, not Project or some other variation.
  • You created an HTML (File > New > HTML file) not a Script file, in the side bar of the Script Editor you must have project.html not a project.html.gs

Script Editor Sidebar