google-apps-script
2012-10-27 109 views 0 likes 
0

直到上週我可以使用下面的html將用戶重定向到另一個頁面,但由於這個星期一這段代碼停止工作在天然氣中(仍然在caja-playground中工作,所以caja不能是源碼的問題)。提交表單使用javascript重定向

任何想法爲什麼會發生?

<html> 
<body> 
    <form action="www.url.com" id='redirect' method='get'> 
    <input type='hidden' name='type' value='hi'> 
    <script> 
     document.getElementById('redirect').submit(); 
    </script> 
    </form> 
</body> 
</html> 

回答

2

是的,他們已經出於安全考慮故意刪除了這個功能。我也不喜歡它,看看我打開的the issue(已經關閉)。

+0

他們應該至少提供一種方法來重定向到同一腳本中的另一個頁面。是的,您可以在提交表單後再投放另一個html文件,但您仍然堅持提交表單的鏈接。 例如 我提交一個表單,得到和我得到一個鏈接,如 '...?type = formSubmit&id = 123' 通常在提交後您將重定向到 '...?type = start' 但現在唯一你可以做的事情是保持在 '...?type = formSubmit&id = 123' 並返回您通常會重定向的頁面的html文件,以打破後退按鈕 –

0

現在,如果你創建一個鏈接與HtmlService:

<a href="?data=12">Redierect to my app"</a> 

天然氣將預先考慮您的腳本URL的HREF。

所以例如表單提交是一個雙擊過程。

<script> 
$('#btnSubmit').click(function(){ 
google.script.run 
.withSuccessHandler(reloadDash) 
.withFailureHandler(foundError) 
.processWelcomeForm(this.parentNode) 
    }); 


function reloadDash(e){ 
$('#btnSubmit').hide(); 
$('#redirectURL').show(); 
} 

function foundError(e){ 
    alert("Oops somthing broke: " + e); 
    } 

</script> 

<html> 
<form id="myForm"> 
<button id="btnSubmit" class="blue">Save Info</button> 
<a href="?setup=1" id="redirectURL" style="display:none"> 
<button id="btnSubmit" class="blue">Saved..continue on with this app</button> 
</a> 
</form> 
相關問題