2012-08-31 24 views
0

我在我的谷歌應用腳​​本項目中的html文件中有一個表單,當點擊一個提交按鈕時,我需要重定向到另一個html文件。如何創建更改頁面的按鈕?

HTML代碼:

<html> 
     <script> 
     function doSomething(){ 
      alert('this one works too!'); 
      //here Change of page 
     } 
     </script> 

    <body> 
     <h1 style="text-align:center;font-family:Tahoma;">HORAS LABORADAS<br/>  
     <form style="margin-left:90px;font-family:Trebuchet MS;"> 
      <b>Nombre</b><br/> 
      <input type="button" onclick="doSomething()"> 
     </form> 
     </body> 
</html> 

我通過

function doGet() { 
    return HtmlService.createTemplateFromFile('prueba').evaluate(); 
} 
+0

請記住,我在谷歌 - 應用程序 - 腳本 – LawCorredor

回答

2

個HTML文件1

 <html> 
      <body> 
      <h1 style="text-align:center;font-family:Tahoma;">HORAS LABORADAS<br/>  
      <form style="margin-left:90px;font-family:Trebuchet MS;"> 
       <b>Nombre</b><br/> 
       <?var url = getUrl();?><a href='<?=url?>?page=2'><input type='button' name='test' value='GO TO PAGE 2'></a> 
      </form> 
      </body> 
    </html> 

HTML文件2

<html> 
    <h1>This is Page 2.</h1><br/> 
<?var url = getUrl();?><a href='<?=url?>?page=1'> <input type='button' name='test' value='RETURN TO PAGE 1'></a> 
</html> 

CODE.GS

function getUrl(){ 
    var url = ScriptApp.getService().getUrl(); 
    return url; 
} 

function doGet(requestInfo) { 
     var url = ScriptApp.getService().getUrl(); 
     if (requestInfo.parameter && requestInfo.parameter['page'] == '2') { 
     return HtmlService.createTemplateFromFile('FILE2').evaluate(); 
     } 
     return HtmlService.createTemplateFromFile('FILE1').evaluate(); 
    } 
0

稱之爲如果你只是想重定向到另一個頁面,使用以下命令:

<script> 
    function doSomething(){ 
     alert('this one works too!'); 
     window.location.href = "http://myurl.com"; 
    } 
</script> 

來源:click this link

+0

我想重定向到另一個文件的工作,我創建!! – LawCorredor

+0

只需將URL替換爲文件的名稱,並確保您的文件和包含表單代碼的文件位於相同的目錄中。 – ThunderCat

+0

它不起作用......請記住,我在google-apps-script中工作 – LawCorredor

相關問題