【发布时间】:2020-12-08 17:55:47
【问题描述】:
我正在使用https://developers.google.com/apps-script/guides/web#embedding_your_web_app_in_google_sites 的说明将已部署的 Google Apps 脚本(如下)的结果嵌入到 Google 站点(新站点)中,但是当我这样做时,我作为Google Apps 脚本的一部分不起作用:“提交”按钮不起作用。
当我直接访问已部署的 Apps 脚本的 URL 时,它运行良好,只有当它嵌入 Google 站点时它才会停止运行。
我已将“部署为 Web 应用”设置为以我身份执行该应用,并将“我的组织内的任何人”设置为有权访问该应用的人。
想法将不胜感激!
代码.gs:
function doGet(e) {
console.log('e object '+ JSON.stringify(e,null,2));
console.log('Active user '+ Session.getActiveUser().getEmail());
var template = HtmlService.createTemplateFromFile('DemoForm.html');
var queryString="none";
if ("queryString" in e.parameters) {
queryString=e.parameters["queryString"];
}
template.queryString = queryString;
//Set the action to come back to this form
template.action = ScriptApp.getService().getUrl();
return template.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
DemoForm.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<h1>Error Demo Form</h1>
<form action="<?= action ?>" method="get">
<label for="queryString">Enter user:</label>
<input type="text" id="queryString" name="queryString">
<input type="submit" value="Submit">
</form>
<h1>Result</h1>
<p>queryString is <?= queryString ?></p>
</body>
</html>
编辑:我通过使用 google.script.run 找到了一种解决方法,正如在 Form redirecting in new google sites 上接受的解决方案中的 cmets 中所述——您可以使用 google.script.run 调用返回原始 HTML 的函数(使用按钮 onclick 触发它),然后使用 withSuccessHandler 更新页面。但我会将这个问题留待几天,看看是否有人有更好/更清洁的解决方案。
【问题讨论】:
标签: google-apps-script google-sites