I have a simple Google WebApps script. It is loading a modal dialog, and then calling a server side function when the dialog is submitted.
This is my html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function handleFormSubmit(formObject) {
google.script.run.processForm(formObject);
google.script.host.close();
}
</script>
</head>
<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<table>
<tr>
<td>My Team</td>
<td><input type="text" name="myTeam"/></td>
</tr>
</table>
<input type="submit" value="Submit" />
</form>
</body>
</html>
This is the script:
function doGet() {
var document = DocumentApp.getActiveDocument();
var ui = document.getBody().appendListItem("hello!")
DocumentApp.getUi()
.createMenu('The Bomb')
.addItem('Simple Kafka Topic', 'sboKafka')
.addSeparator()
.addToUi();
}
function sboKafka() {
var html = HtmlService.createHtmlOutputFromFile('SBOKafka')
.setWidth(400)
.setHeight(300);
DocumentApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
.showModalDialog(html, 'Simple Kafka Topic');
}
function processForm(formObject) {
Logger.log("processForm");
var zt = formObject.myTeam;
DocumentApp.getActiveDocument().getBody().appendListItem(zt)
}
However, when the dialog is submitted, the server side function is not run.
I am seeing the following error in the browser error console.
Unsafe JavaScript attempt to initiate navigation for frame with origin 'https://docs.google.com' from frame with URL 'https://n-e2b764askqfnjofaraeymmf47os6fnoc372huli-0lu-script.googleusercontent.com/userCodeAppPanel'.
The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.
Any idea what I am doing wrong?
UPDATE 1: This is how I am testing this out....
- Close the script editor window and the google doc.
- Go to Drive -> Open the Doc
- Click on Tools -> Script Editor. This opens the script editor window
- Go to script editor window
- Click on Run -> Run Function -> doGet
- Go back to word doc. Click on The Bomb -> Simple Kafka Topic
- Dialog pops up.
- Enter a string in team name.
- Submit
- Nothing happens
Expected: Text in document to change.