Google Apps 脚本删除警告横幅
Google Apps Script remove warning banner
我正在使用 Google Apps 脚本在我的 Google 网站上放置 GeoChart。当我未登录我的 google 帐户时查看页面会在顶部显示一个灰色横幅,状态为:"This application was created by another user, not by Google." 看到它 here。
有没有办法删除此横幅或将其移至页面底部以使其看起来更好?我发现了一个简短的讨论 here(见第四条评论),但这不适用于我在 doGet
中使用的 HtmlOutput 对象
function doGet() {
return HtmlService.createHtmlOutputFromFile('prate').setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
似乎可以从使用 HtmlService 的 WebApp 中抑制该警告的两个选项是:
自定义 CSS,例如在 Stylesheet.html 中(假设您是从 WebApp 脚本模板开始的)。
.warning-bar {
visibility: hidden;
}
这个我试过了,发现对最后的显示没有影响。如果在 iframe 的 HTML 中有一个带有 class="warning-bar"
的元素, 该元素 将被隐藏。同样,如果我们尝试通过 id 修改警告栏,#warning
;对 iframe 之外的元素没有影响。
没有CSS对父元素的支持,所以这是死胡同。
使用客户端 JavaScript 来操作我们的 iframe 之外的元素。通过向 JavaScript.html 添加代码(再次假设 WebApp 脚本模板),我们可以尝试更改文档元素。
与jQuery:
$('.warning-bar:first',parent.document).hide();
纯JavaScript:
top.getElementById('warning').style.display = 'none';
这些都不起作用。 Google 用于托管 Google Apps 脚本的配置会阻止 iframe 中的 JavaScript 运行 访问父页面中的项目。这是 JavaScript 控制台中显示的错误:
Uncaught SecurityError: Blocked a frame with origin "https://n-gtoiuxrqufcpexrnkeysovsfb7ibnjwczjyz6ii-script.googleusercontent.com" from accessing a frame with origin "https://script.google.com". Protocols, domains, and ports must match.
他们强制我们脚本的 iframe 有一个不同于周围文档的主机域,使单域安全策略能够阻止我们正在尝试执行的确切操作。
根据您在问题中链接到的问题,避免该烦人消息的唯一选择是切换到付费 Google 应用程序域(例如商业或教育)。
对于任何关心的人,我通过在 iframe 中嵌入一个包含此问题的 google 页面并使用负边距来解决这个问题。看不到酒吧。只是把它扔出去 in-case 任何人都可以使用这个建议
为此,我成功地使用了 Chrome 扩展 Custom JavaScript for websites。它允许您 运行 任何域上的任何 JavaScript。
要隐藏 Google 警告横幅,只需在自定义 JavaScript window 中输入以下代码:
document.getElementById('warning').style.display = 'none';
然后点击 保存。它会立即应用。
如果将其嵌入 google site 横幅将不会显示。
如果您使用 IFRAME 标签将 Google Script 网络应用程序嵌入到另一个网站,警告横幅将被隐藏。确保将页面的 X-Frame-Options
header 设置为 XFrameOptionsMode.ALLOWALL
并且它将允许任何网站 iframe 网络应用程序页面。
参见docs。
我正在使用 Google Apps 脚本在我的 Google 网站上放置 GeoChart。当我未登录我的 google 帐户时查看页面会在顶部显示一个灰色横幅,状态为:"This application was created by another user, not by Google." 看到它 here。
有没有办法删除此横幅或将其移至页面底部以使其看起来更好?我发现了一个简短的讨论 here(见第四条评论),但这不适用于我在 doGet
function doGet() {
return HtmlService.createHtmlOutputFromFile('prate').setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
似乎可以从使用 HtmlService 的 WebApp 中抑制该警告的两个选项是:
自定义 CSS,例如在 Stylesheet.html 中(假设您是从 WebApp 脚本模板开始的)。
.warning-bar { visibility: hidden; }
这个我试过了,发现对最后的显示没有影响。如果在 iframe 的 HTML 中有一个带有
class="warning-bar"
的元素, 该元素 将被隐藏。同样,如果我们尝试通过 id 修改警告栏,#warning
;对 iframe 之外的元素没有影响。没有CSS对父元素的支持,所以这是死胡同。
使用客户端 JavaScript 来操作我们的 iframe 之外的元素。通过向 JavaScript.html 添加代码(再次假设 WebApp 脚本模板),我们可以尝试更改文档元素。
与jQuery:
$('.warning-bar:first',parent.document).hide();
纯JavaScript:
top.getElementById('warning').style.display = 'none';
这些都不起作用。 Google 用于托管 Google Apps 脚本的配置会阻止 iframe 中的 JavaScript 运行 访问父页面中的项目。这是 JavaScript 控制台中显示的错误:
Uncaught SecurityError: Blocked a frame with origin "https://n-gtoiuxrqufcpexrnkeysovsfb7ibnjwczjyz6ii-script.googleusercontent.com" from accessing a frame with origin "https://script.google.com". Protocols, domains, and ports must match.
他们强制我们脚本的 iframe 有一个不同于周围文档的主机域,使单域安全策略能够阻止我们正在尝试执行的确切操作。
根据您在问题中链接到的问题,避免该烦人消息的唯一选择是切换到付费 Google 应用程序域(例如商业或教育)。
对于任何关心的人,我通过在 iframe 中嵌入一个包含此问题的 google 页面并使用负边距来解决这个问题。看不到酒吧。只是把它扔出去 in-case 任何人都可以使用这个建议
为此,我成功地使用了 Chrome 扩展 Custom JavaScript for websites。它允许您 运行 任何域上的任何 JavaScript。
要隐藏 Google 警告横幅,只需在自定义 JavaScript window 中输入以下代码:
document.getElementById('warning').style.display = 'none';
然后点击 保存。它会立即应用。
如果将其嵌入 google site 横幅将不会显示。
如果您使用 IFRAME 标签将 Google Script 网络应用程序嵌入到另一个网站,警告横幅将被隐藏。确保将页面的 X-Frame-Options
header 设置为 XFrameOptionsMode.ALLOWALL
并且它将允许任何网站 iframe 网络应用程序页面。
参见docs。