Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

html - href in HtmlService

I have 2 html documents inside my google apps script project (showHtml1, showHtml2). I serve the first one by

function doGet() {
    return HtmlService.createTemplateFromFile('showHtml1').evaluate();
}

and inside the first html i want to include the href to the second html (showHtml2). Is that possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This sample should show you the pattern. You can use Html files wherever I used HtmlOuput objects. I just wanted to keep it simple.

function doGet(requestInfo) {
  var url = ScriptApp.getService().getUrl();
  if (requestInfo.parameter && requestInfo.parameter['page'] == '2') {
    return HtmlService.createHtmlOutput(
      "This is Page 2. <a href='" + url + "?page=1'>Page 1</a>");
  }
  return HtmlService.createHtmlOutput(
      "This is Page 1. <a href='" + url + "?page=2'>Page 2</a>");
}

Bear in mind when working with this that the URL from ScriptApp will be the deployed url, not the dev mode url, so if you are experimenting you might want to replace the "/exec" at the end with "/dev".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...