Web应用程序HTML,JS + Google Apps脚本:返回GAS后如何返回到我的应用程序? [英] Web App HTML, JS + Google Apps Script: How to go back to my app after return in GAS?
问题描述
我使用HTML,CSS和JavaScript构建了一个Web应用程序,并使用Google Spreadsheet作为数据库。我打算使用 PhoneGap 将我的网络应用程序变成真正的应用程序。
我能够从Google表格中读取,使用Google Visualization API,现在我正在研究编写选项:我在Google Spreadsheet中使用了一个包含 Google Apps脚本的功能集,并且它可以正常工作。
这是我的应用程序的工作原理和我需要的:
- Google Spreadsheet(数据库)
- 如果找不到我需要的内容,我可以提出请求
- 发送请求:表单的动作将数据发送到Google Apps脚本代码
- GAS将我的数据写入第二个Google电子表格(注册表)
- 该页面在屏幕上发送反馈
正如你大胆的理解,我无法回到我的w ebpages ...我不知道是否有任何方法或功能来做到这一点。我唯一发现的是使用 ContentService
使页面写入另一个表单并使用JavaScript发送,但我认为这不是最好的解决方案...
我会在这里发布我的代码...希望有人能帮助我
function doPost(e){
var sheet = SpreadsheetApp.openById(myID)。getSheetByName('SheetName');
var column = 1;
var colArray = sheet.getRange(2,column,sheet.getLastRow())。getValues();
var maxi = Math.max.apply(Math,colArray);
var id = maxi + 1;
var name = e.parameter ['name'];
var surname = e.parameter ['surname'];
var serial = e.parameter ['serial'];
var eMail = e.parameter ['mail'];
var text = e.parameter ['text'];
var area = e.parameter ['area'];
var date = new Date();
var ans =
var flag =工作进行中;
var vals = [id,日期,姓名,序列号,电子邮件,区域,文本,ans,标志];
var sheetObj = sheet.appendRow(vals);
//返回ContentService.createTextOutput(someOutput);
在返回行中,我应该返回到我的网络应用程序/应用程序,但我无法找到方法来做到这一点。有人可以帮我或给我一些建议吗?
非常感谢您的帮助!
/ p>
这是解决您的问题的方法。 return ContentService.createTextOutput(someOutput);
使用 HtmlService
返回你的表单
return HtmlService.createHtmlOutputFromFile('redirect')。setSandboxMode(HtmlService.SandboxMode.IFRAME);
你的HTML文件应该是这样的,
更新: redirect.html
应与您的应用脚本文件位于同一个项目中。
redirect.html
< html> ;
< head>
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js>< / script>
< title>这是样本标题< / title>
< script>
function test()
{
window.location.href =www.hostname.com;
}
< / script>
< / head>
< body onload =test()>
登入
< / body>
< / html>
看看这是否适合您。
I'm building a web app using HTML, CSS and JavaScript and using Google Spreadsheet as a database. I'm planning to use PhoneGap to turn my web app into a real app.
I was able to read from my Google Sheet, using the Google Visualization API, now I'm working about the writing options: I used a function set with Google Apps Script, inside the Google Spreadsheet and it works correctly.
This is how my app works and what I need:
- I query my first Google Spreadsheet (Database)
- If I cannot find what I need, I can make a request
- I send the request: the action of the form send my data to the Google Apps Script code
- The GAS writes my data in a second Google Spreadsheet (Register)
- The GAS should send me back to my page
- The page sends a feedback on screen
As you can understand by the bold point, I'm not able to go back to my webpages... I don't know if there's any method or function to do this. The only thing I found was using ContentService
to make the page "write another form and send it using JavaScript", but I don't think is the best solution...
I'll post my code down here... hoping someone can help me
function doPost(e){
var sheet = SpreadsheetApp.openById("myID").getSheetByName('SheetName');
var column = 1;
var colArray = sheet.getRange(2, column, sheet.getLastRow()).getValues();
var maxi = Math.max.apply(Math, colArray);
var id = maxi+1;
var name = e.parameter['name'];
var surname = e.parameter['surname'];
var serial = e.parameter['serial'];
var eMail = e.parameter['mail'];
var text = e.parameter['text'];
var area = e.parameter['area'];
var date = new Date();
var ans = ""
var flag = "Work In Progress";
var vals = [id, date, name, surname, serial, eMail, area, text, ans, flag];
var sheetObj = sheet.appendRow(vals);
// return ContentService.createTextOutput(someOutput);
On the return line I should go back to my web app/app but I can't find a way to do it. Someone can help me or give me some advice?
Thanks a lot for your help!
S.
This is the solution to your problem.
Instead of using return ContentService.createTextOutput(someOutput);
use HtmlService
to return to your form
return HtmlService.createHtmlOutputFromFile('redirect').setSandboxMode(HtmlService.SandboxMode.IFRAME);
And your HTML file should look like this,
Update: redirect.html
should be in the same project as that of your app script file.
redirect.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<title>This Is A Sample Title</title>
<script>
function test()
{
window.location.href = "www.hostname.com";
}
</script>
</head>
<body onload="test()">
Login
</body>
</html>
See if this works for you.
这篇关于Web应用程序HTML,JS + Google Apps脚本:返回GAS后如何返回到我的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!