【发布时间】:2020-11-24 01:25:19
【问题描述】:
我有一个简单的 Google WebApps 脚本。它正在加载一个模态对话框,然后在提交对话框时调用服务器端函数。
这是我的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>
这是脚本:
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)
}
但是,当对话框提交时,服务端函数并没有运行。
我在浏览器错误控制台中看到以下错误。
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.
知道我做错了什么吗?
更新 1:这就是我测试它的方式......
- 关闭脚本编辑器窗口和谷歌文档。
- 转到云端硬盘 -> 打开文档
- 单击工具 -> 脚本编辑器。这将打开脚本编辑器窗口
- 转到脚本编辑器窗口
- 点击运行->运行函数->doGet
- 返回 Word 文档。点击炸弹 -> 简单的卡夫卡主题
- 弹出对话框。
- 在团队名称中输入一个字符串。
- 提交
- 什么都没有发生
预期:文档中的文本要更改。
【问题讨论】:
标签: javascript html google-apps-script