1

我通过谷歌应用脚​​本中的 Html Services api 创建了一个网页。在脚本中,我有一个 google 脚本(.gs)文件和两个 html 文件(.html)。该脚本发布在网络上。为了在 web 上显示 html 文件,我在 .gs 文件中使用了以下函数:

function doGet() {   //Published on web
  return HtmlService.createTemplateFromFile('<htmlFile_1>').evaluate();
}

function doProcess() {
  return HtmlService.createTemplateFromFile('<htmlFile_2>').evaluate();
}

doGet() 在网络上返回这个 Html 文件。现在我想通过替换这个文件来显示另一个 Html 文件。所以,我在 htmlFile_1 中使用了以下内容:

//htmlFile_1.html

<html>
  <head>
  <script>
    function loadMainHtmlPage(){
       google.script.run.doProcess();     //calling another function in .gs file
       setTimeout(function(){hello()},4000);

    }

    function hello(){
    alert("hiii");
     document.getElementById("loading").style.display="none";}

  </script>
</head>

<body onload="loadMainHtmlPage();">
   <div id="loading" style="display:block;">
      <img src="http://commondatastorage.googleapis.com/kickoff/loading.gif"/>
 </div>
  </body>

</html>

这个 htmlFile_1 没有调用 doProcess(),它会返回 htmlFile_2。有什么建议可以实施吗?

4

1 回答 1

2

您需要在这行代码中包含一个 onSuccess(以及可选的 onFailure)处理程序

google.script.run.doProcess();

见下文

Server code
function getSuperHero() {
  return {name: "SuperGeek",  catch_phrase: "Don't worry ma'am, I come from the Internet" };
}

Client code
<script>
  function onSuccess(hero) {
    alert (hero.catch_phrase);
  }
  google.script.run.withSuccessHandler(onSuccess).getSuperHero();
</script>
于 2012-12-18T12:38:36.693 回答