1

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>

Then comes server-side function:

function includeCSS() { 
var content = HtmlService.createTemplateFromFile('MainPageCSS').getRawContent();
  //.getContent();
return content;
}

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);
};

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>

Also sidebar is launched in SandBox.Native mode, so it allows css dynamic changes. Thank you for help.

1 Answer 1

0

In my website, I use a scriptlet to include the CSS file.

HTML:

<?!= include('MainPageCSS'); ?>

<div>Some Content Here</div>
<form>A form</form>
<button>A button</button>

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.