Google应用程式指令码:分隔HTML和CSS [英] Google app script : Separating HTML and CSS
问题描述
我有一个与标题相关的问题。目前我想跟着google最佳实践。 https://developers.google.com/apps-script/guides/html / best-practices
我不知道为什么它不工作。
这里是MainPageCSS.html
i have a question connected with title. Currently i am trying to follow google "best practice". https://developers.google.com/apps-script/guides/html/best-practices I have no idea why its not working. Here is a MainPageCSS.html
<pre>
<style>
p {
color: green;
}
</style>
</pre>
服务器端功能:
function includeCSS() {
var content = HtmlService.createTemplateFromFile('MainPageCSS').getRawContent();
//.getContent();
return content;
}
我通过HtmlService使用侧边栏,并调用google.script.run。 withSuccessHandler(SuccessAddCss).includeCSS();
我尝试了不同的方式添加css到页面,但没有工作...
I am using a sidebar via HtmlService, and calling google.script.run.withSuccessHandler(SuccessAddCss).includeCSS(); I tried different ways of adding css into page, but noone worked...
function SuccessAddCss(Style){
var styles = document.getElementById("allStyles").innerHTML += "p { color:red }";
var text = styles.innerHTML;
var styleNode = document.createElement('style');
var styleText = document.createTextNode('p { color:red; } ');
styleNode.appendChild(styleText);
document.getElementsByTagName('head')[0].appendChild(styleNode);
alert("ok");
};
function teso()
{
google.script.run.withSuccessHandler(SuccessAddCss).includeCSS();
alert(text);
};
为了将MainPageCSS中的css添加到MainPage
id =allStylestype = text / css
In order to add somehow css from MainPageCSS to MainPage id="allStyles" type="text/css"
<pre>
<style id="allStyles" type="text/css">
h2{
font-family: Times New Roman, Times, serif;
font-size: 14px;
text-align: center;
}
</style>
</pre>
此外,Sidebar在SandBox.Native模式下启动,因此允许css动态更改。
Also sidebar is launched in SandBox.Native mode, so it allows css dynamic changes. Thank you for help.
推荐答案
在我的网站上,我使用一个脚本来包含CSS文件。 p>
HTML:
In my website, I use a scriptlet to include the CSS file.
<?!= include('MainPageCSS'); ?>
<div>Some Content Here</div>
<form>A form</form>
<button>A button</button>
这是 include
HTML文件。只要好奇,你能尝试取出< pre>
标签,看看是否有什么区别?
That's how the include
function gets called from the HTML file. Just curious, could you try taking out the <pre>
tags and see if that makes any difference?
这篇关于Google应用程式指令码:分隔HTML和CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!