2012-12-18 27 views
1

我已經通過谷歌應用腳​​本中的Html服務api創建了一個網頁。在腳本中,我有一個谷歌腳本(.gs)文件和兩個html文件(.html)。該腳本在網上發佈。在網上顯示html文件我在.gs文件中使用了以下功能:如何從HTML文件調用谷歌腳本功能?

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」 任何建議來實現這個?

回答

1

您需要包括的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> 
相關問題