HtmlService中的href [英] href in HtmlService

查看:85
本文介绍了HtmlService中的href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的google apps脚本项目(showHtml1,showHtml2)中有2个html文档。
我服务第一个

$ p $函数doGet(){
')。评估();
}

和第一个html里面我想包含href到第二个html showHtml2)。
是否有可能?

解决方案

此示例应该会显示您的模式。您可以在任何使用HtmlOutput对象的地方使用Html文件。


$ b

 函数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'>页面1< / a>);
}
return HtmlService.createHtmlOutput(
This is Page 1.< a href ='+ url +?page = 2'> Page 2< / a>) ;

请记住,在处理ScriptApp的URL时, url,而不是dev模式的url,所以如果你正在尝试你可能想用/ dev替换/ exec。


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?

解决方案

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

这篇关于HtmlService中的href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆