I created a simple web app, and it is not working.
Code.gs:
function doGet() {//I think this works
var output = HtmlService.createTemplateFromFile(\'in
There are quite few errors in your code.
code.gs
function doGet() {
var output = HtmlService.createTemplateFromFile('index').evaluate();
output.setSandboxMode(HtmlService.SandboxMode.IFRAME);
output.setTitle('email button');
return output;
}
function getContent(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
index.html
<!DOCTYPE html>
<html>
<body>
<form id="email_subscribe">
<input type="email" name="email" id="email" placeholder="Enter your email">
<input type="button" id="submitButton" value="Submit">
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<?!= getContent("javascriptCode") ?>
</body>
</html>
javascriptCode.html
<script type="text/javascript">
$(document).ready(function() {
$("#submitButton").click(function() {
alert('thx for submitting');
});
});
</script>
I usually test these things as a dialog to get them working. It's works as a dialog and I've also included the doGet. I hope this helps. I didn't go exactly as you were going but I think this will help you move that way.
Code.gs:
function doGet()
{
var output = HtmlService.createTemplateFromFile('webappdoesnotwork');
return output.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
}
function getEmail(email)
{
Logger.log(email);
return true;
}
function showDialog()
{
var output = HtmlService.createHtmlOutputFromFile('webappdoesnotwork');
SpreadsheetApp.getUi().showModelessDialog(output, 'My WebApp');
}
webappdoesnotwork.html
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function getEmail()
{
var email=$('#email').val();
google.script.run
.withSuccessHandler(sayThanks)
.getEmail(email);
}
function sayThanks()
{
$('#saythanks').css('display','block');
$('#controls').css('display','none');
}
console.log('My Code');
</script>
</head>
<body>
<div id="saythanks" style="display:none">Hey Thanks for Responding</div>
<div id="controls">
<input type="text" id="email" size="35" placeholder="Enter your email"/>
<input type="button" id="submitButton" value="Submit" onClick="getEmail();"/>
</div>
</body>
</html>