href in HtmlService

前端 未结 2 1152
你的背包
你的背包 2020-12-08 18:13

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

function doGet() {
    return HtmlService.crea         


        
相关标签:
2条回答
  • Yes you can follow the above tip but build the template from your html file, something as this:

    function doGet() {
      var template;
      if(parameter.page='html01') {
        template= HtmlService.createTemplateFromFile('fileHtml01');
         template.page='html01';
      } else {
         template= HtmlService.createTemplateFromFile('fileHtml02');
         template.page='html02';
      }
      return template.evaluate();
    }
    

    and according the paramater show one url or the other one.

    0 讨论(0)
  • 2020-12-08 18:40

    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".

    0 讨论(0)
提交回复
热议问题