为观众展示侧边栏 [英] Showing sidebar for viewers

查看:104
本文介绍了为观众展示侧边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何显示匿名观看者(或编辑者)的边栏?
我试过使用正常的和可安装的触发器:
$ b

正常触发器:

  function onOpen(){
var html = HtmlService.createHtmlOutputFromFile('Page')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('我的自定义边栏')
.setWidth(300);
SpreadsheetApp.getUi()//或DocumentApp或FormApp。
.showSidebar(html);
}

这与电子表格的所有者合作,但不适用于匿名用户尽管任何有链接的人都有编辑权限。



可安装触发器:

  function showSidebar(){
...与前面的'onOpen'函数相同的主体
}

然后,我将函数showSidebar绑定到电子表格打开时调用的可安装触发器。



这不适用于所有者或匿名用户!



最后,我尝试将函数showSidebar绑定到插入到电子表格中的图像,但未与匿名用户一起使用。它会显示一条消息:


脚本showSidebar遇到错误

,即使最终方法运行良好,它也不会自动显示侧边栏。

我的代码几乎与 https://developers.google.com/应用程序脚本/引导/对话框#custom_sidebars 的。这有两个文件Code.gs和Page.html。由于OP没有提及Page.html的代码,很可能是因为使用与OP相同的代码而错过了尝试,因为如果Page.html文件的代码包含并且文件已打开由编辑负责。



关于以匿名用户身份运行,当电子表格由具有查看或编辑权限的匿名用户打开时,onOpen不会运行。 Google Apps Issue Tracker中有与此相关的报告。

问题:5747为匿名用户匿名用户/脚本触发



更新:



answer 通过 + Samantha Google文档帮助论坛中的类似主题


为了使脚本在Google表格上运行,用户必须记录
并拥有可编辑权限。这意味着匿名用户
不能运行脚本。

如果您希望将此功能添加到脚本中,那么I
建议导航至Google Developers的Apps Script支持
页面并按下发送反馈按钮。




来自第一个链接的代码

Code.gs

  function onOpen(){
SpreadsheetApp.getUi()//或DocumentApp或FormApp。
.createMenu('Custom Menu')
.addItem('Show sidebar','showSidebar')
.addToUi();


函数showSidebar(){
var html = HtmlService.createHtmlOutputFromFile('Page')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('我的自定义边栏')
.setWidth(300);
SpreadsheetApp.getUi()//或DocumentApp或FormApp。
.showSidebar(html);

Page.html

 你好,世界! < input type =buttonvalue =Closeonclick =google.script.host.close()/> 


How can I show the sidebar for anonymous viewers (or editors)? I tried using normal and installable triggers:

Normal Triggers:

function onOpen(){
  var html = HtmlService.createHtmlOutputFromFile('Page')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setTitle('My custom sidebar')
  .setWidth(300);
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
  .showSidebar(html);
}

This worked with the owner of the spreadsheet but didn't work with anonymous users although anyone with the link has editing permission.

Installable Triggers:

function showSidebar(){
  ... the same body of the previous 'onOpen' function
}

Then, I bound the function showSidebar to an installable trigger that is called when the spreadsheet is opened.

This didn't work with either the owner or an anonymous user!

Finally, I tried binding the function showSidebar to an image inserted into the spreadsheet but didn't work with an anonymous user. It displays a message saying

Script showSidebar experienced an error

and even if the final method worked well, it will not show the sidebar automatically.

解决方案

It looks to me that the code is almost the same of https://developers.google.com/apps-script/guides/dialogs#custom_sidebars. That has two files, Code.gs and Page.html. As the OP didn't mentioned the code of Page.html it's very likely that it was missing on his attempt as using the same code as the OP worked just fine if the code of the Page.html file is include and the file is opened by the owner of by an editor.

Regarding running as anonymous user, the onOpen doesn't run when the spreadsheet is opened by an anonymous with view or edit access. There is a report related to this in the Google Apps Issue Tracker

Issue: 5747 Trigger for anonymous user / script for anonymous user


UPDATE:

From an answer by +Samantha to a similar thread in the Google Docs Help Forum

In order for Scripts to run on a Google Sheet, the user must be logged in and have "can edit" rights. This means that anonymous users will not be able to run a Script.

If you would like to see this functionality added to Scripts, I recommend navigating to the Google Developers' Apps Script support page and pressing the "Send Feedback" button.


Code from the first link

Code.gs

function onOpen() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Custom Menu')
      .addItem('Show sidebar', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('Page')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('My custom sidebar')
      .setWidth(300);
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);

Page.html

Hello, world! <input type="button" value="Close" onclick="google.script.host.close()" />

这篇关于为观众展示侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆