我正在尝试遵循Google针对Google Apps脚本对话框迁移到IFRAME的指导原则。但是,我迁移的所有对话框都不再起作用 - 只显示标题,并且以下错误将显示在控制台上:"未捕获的TypeError:无法读取属性' call'未定义"。
以下是问题简单示例的链接:https://docs.google.com/spreadsheets/d/1n5Lr6LuMj4Cyag4Z_54jRKvWiwV-b8dquREF5T4pzMY/edit?usp=sharing
这是一个空白的电子表格,其中添加了#34;对话框"菜单,选择"显示对话框"来自" Dialog"菜单来查看行为。
function onOpen()
{
SpreadsheetApp.getUi().createMenu("Dialog")
.addItem("Show Dialog","showDialog")
.addToUi();
}
function showDialog()
{
var html = HtmlService.createHtmlOutputFromFile('Index').setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Dialog title');
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
function onOK()
{
console.log("ok");
}
function onCancel()
{
console.log("cancel");
}
</script>
</head>
<body>
<div>
<input type="text" id="editme" size="8">
<button type="button" id="ok" style="display: block; position: absolute; top: 150px; width: 60px;" onclick="onOK()">OK</button>
<button type="button" id="cancel" style="display: block; position: absolute; top: 150px; left: 100px; width: 60px;" onclick="onCancel()">Cancel</button>
</div>
</body>
</html>
答案 0 :(得分:0)
实际上,几个月前已经在 google-apps-scripts-issues 中针对HTMLService migration to IFRAME sandbox fails: Cannot read property 'call' of undefined记录了现有问题。基于该问题线程,一些开发人员也遇到了它,但尚未解决。
在任何情况下,您可能都想尝试检查并注意HTML Service: Restrictions和HTML Service: Best Practices,但可能只会遗漏某些内容。
也可以在此SO帖子中尝试建议的解决方案 - IFRAME and NATIVE Mode in Google Apps Script。我希望这些东西能为你起作用。