In a Google Apps Script, I have the following script:
function doGet() {
return HtmlService.createHtmlOutputFromFile('mypage');
}
function writeSomething() {
return "<h1>hi people</h1>";
}
and the following html file:
<html>
<a id="caller" href="#">update</a>
<br>
<div id="div">waiting...</div>
<script>
function go() {
var a=google.script.run.writeSomething();
document.getElementById("div").innerHTML=a;
}
document.getElementById('caller').onclick = go;
</script>
</html>
When I click on the "update" link, the div content changes from "waiting..." to "undefined". I suppose that google.script.run cannot be called as a function.
So, how can I solve this trouble? (obviously, this is a toy example; I need a way to update the div content from the script and not from the html file)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…