I cannot get my Apps Script-based HTML to include any scripts.
My doGet
function for the HtmlService
works fine:
function doGet() {
return HtmlService.createHtmlOutputFromFile('myhtmlfilename');
}
I seem to get the following whether or not I have any script tags on my HTML file:
I have tried storing all of my JavaScript in a separate HTML file with tags (called JavaScript.html
) and then including them back into my HTML using force print scriptlets.
My HTML file containing my script tags:
<script>
function transferItems(){
google.script.run.test();
}
</script>
My function to include the script HTML as a scriptlet, which I have also tried as 'getRawContent' instead of 'evaluate':
function include(filename) {
return HtmlService.createTemplateFromFile(filename).evaluate().getContent();
}
My scriptlet:
<?!= include('JavaScript'); ?>
My function in my code.gs, called test()
:
function test() {
alert("This is a test.");
}
My button in my main HTML page through which I am trying to call the test()
function:
<button onClick="transferItems()">Transfer</button>
No matter what I try my page ends up displaying those scriptlets as text in the browser.
What am I missing?
All of the answers and tutorials I have read are from 2015ish or earlier. I feel like I am following Google's documentation.