Javascript 带有多个样式表和js链接的Google应用程序脚本
我是谷歌应用程序脚本的新手,正在尝试在我的谷歌网站上实现一个新的应用程序 我已经在脚本编辑器中将css样式表和.js文件分离为.html,并编写了html pageminigallery.html,现在我正在尝试在Code.gs部分链接它们。以下是我迄今为止使用的示例: 下面是我目前在Code.gs中的内容,但是当我运行发布的版本时,css&js文件似乎没有链接,即使我还没有放图片。您可以在此处找到已发布的链接: //script.google.com/macros/s/akfycbybcctw9y-iCT81WvBoCmfGnXWhSwQ5dpa7xyHU_H1ot/devJavascript 带有多个样式表和js链接的Google应用程序脚本,javascript,jquery,html,css,google-apps-script,Javascript,Jquery,Html,Css,Google Apps Script,我是谷歌应用程序脚本的新手,正在尝试在我的谷歌网站上实现一个新的应用程序 我已经在脚本编辑器中将css样式表和.js文件分离为.html,并编写了html pageminigallery.html,现在我正在尝试在Code.gs部分链接它们。以下是我迄今为止使用的示例: 下面是我目前在Code.gs中的内容,但是当我运行发布的版本时,css&js文件似乎没有链接,即使我还没有放图片。您可以在此处找到已发布的链接: //script.google.com/macros/s/akfycbybcct
`
// Script-as-app template.
function doGet() {
var app = UiApp.createApplication().setTitle('Business Card Mini Gallery | MAvC Graphics.').setHeight(50).setWidth(100)
return HtmlService.createTemplateFromFile('minigallery')
.evaluate();
}function include(customcss) {
return HtmlService.createHtmlOutputFromFile('customcss')
.getContent();
}function include(layoutcss) {
return HtmlService.createHtmlOutputFromFile('layoutcss')
.getContent();
}function include(minigallerycss) {
return HtmlService.createHtmlOutputFromFile('minigallerycss')
.getContent();
}function include(eyesjs) {
return HtmlService.createHtmlOutputFromFile('eyejs')
.getContent();
}function include(jqueryjs) {
return HtmlService.createHtmlOutputFromFile('jqueryjs')
.getContent();
}function include(layoutjs) {
return HtmlService.createHtmlOutputFromFile('layoutjs')
.getContent();
}function include(utilsjs) {
return HtmlService.createHtmlOutputFromFile('utilsjs')
.getContent();
}function include(minigalleryjs) {
return HtmlService.createHtmlOutputFromFile('minigalleryjs')
.getContent();
}
`
下面是我写得不好的minigallery.html代码,用于链接css和js最重要的第一行和最后一行:
<?!= include('customcss'), ('layoutcss'), ('minigallerycss'); ?>
...//lengthy inner page code
<?!= include('eyejs'), ('jqueryjs'), ('layoutjs'), ('minigalleryjs'), ('utilsjs'); ?>
为了使事情复杂化,我将整个东西从spacegallery重命名为minigallery,但我已经适当地更改了所有文件。您只需要一个名为include的函数。现在有很多函数都命名为Include 要查找的文件名将传递给include函数:
<?!= include('Stylesheet'); ?>
在.gs文件中,只有一条include语句:
代码.gs
该代码直接取自文档。filename是一个变量,它可以接受传递给它的任何值
您可以将HTML与UI服务一起使用。请参阅以下链接:
但是,我认为不能同时使用HTML和UI服务。我找不到任何能说明这一点的东西,但我知道我过去试过。所以,我很确定你需要决定其中一个。但是,如果有人知道一种方法,我当然想知道怎么做。你有什么具体的问题吗?将css和js文件链接到html,因为当我查看发布的页面时,它显示没有样式或操作,我没有得到任何调试错误,我实际上已经解决了!原来我不需要包含。下面是我的代码.gs:函数doGet{var result=HtmlService.createTemplateFromFile'minigallery'。求值;返回结果;}函数getContentfilename{var return1=HtmlService.createTemplateFromFile'minigallery'。getRawContent;返回1;}还有我的minigally.htmlpg:哦,我不能发布它,因为代码太长了&我还是新手。你可以在这里查看:所以现在我只需要更新图片以使其看起来更好&使用最近完成的名片&我完成了!
<?!= include('customcss'); ?>
<?!= include('layoutcss'); ?>
<?!= include('minigallerycss'); ?>
<?!= include('eyesjs'); ?>
<?!= include('jqueryjs'); ?>
etc.
function doGet() {
return HtmlService.createTemplateFromFile('minigallery')
.evaluate() // evaluate MUST come before setting the NATIVE mode
.setTitle('Business Card Mini Gallery | MAvC Graphics.')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename)
.getContent();
}