In this post, I show three different examples of how to use the doGet(e) function to start the HTML Google Web Application.
How to Video:
Video Notes:
- Legacy Apps Script Editor Used in Video
- Apps Script (Script Editor) is now located under tab ‘Extensions’ instead of ‘Tools’ on Google Sheets
- Google Web Application Documentation
- Templated HTML Documentation
Code in Video:
Google Apps Script Code Used in Video Below:
function doGet(e) {
Logger.log(JSON.stringify(e));
Logger.log(e.parameter['message']);
return HtmlService.createHtmlOutputFromFile('ExampleFile1');
}
//function doGet(e)
//{
// Logger.log(JSON.stringify(e));
// Logger.log(e.parameter['message']);
// var htmlOutput = HtmlService.createTemplateFromFile('ExampleFile2');
// htmlOutput.message = e.parameter['message'];
// return htmlOutput.evaluate();
//}
//function doGet(e)
//{
// Logger.log(JSON.stringify(e));
// var htmlOutput = HtmlService.createTemplateFromFile('ExampleFile3');
// if(!e.parameter['username'])
// {
// htmlOutput.username = '';
// }
// else
// {
// htmlOutput.username = 'Username is: ' + e.parameter['username'];
// }
// htmlOutput.url = getUrl();
// return htmlOutput.evaluate();
//}
//
//
//function getUrl() {
// var url = ScriptApp.getService().getUrl();
// return url;
//}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>Example File 1</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>Example File 2</h1>
<span><?= message ?></span>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>Example File 3</h1>
<form action="<?= url ?>" method="GET" >
<input type="text" name="username" />
<input type="submit" name="Submit" /><br>
<span><?= username ?></span>
</form>
</body>
</html>
Related Posts
How to use the onOpen(e) Function on Google Sheets - In this post, I show how to use the Google Apps Script onOpen(e) Trigger Function on Google Sheets. I show two examples of how the function can be used.
Copy Row Using onSelectionChange(e) Trigger on Google Sheets - In this post, I demonstrate how to use the onSelectionChange(e) trigger function in an application that copies Rows from one sheet to another.
How to use the onEdit(e) Function on Google Sheets - In the Post, I demonstrate how to use the onEdit(e) Function on Google Sheets. This video focuses on the editing of one cell.