Google Apps脚本中是否有一种方法可以上传数据并在之后打开新标签?(Is there a way in Google Apps Script to upload data and to ope

编程入门 行业动态 更新时间:2024-10-09 22:22:18
Google Apps脚本中是否有一种方法可以上传数据并在之后打开新标签?(Is there a way in Google Apps Script to upload data and to open a new tab afterwards?)

我们为Google表格提供Google Aops脚本以与我们的服务器进行交互。

我们需要导出所选数据,而不是打开一个新的浏览器选项卡(从我们的服务器)。

目前我们在侧边栏中有一个按钮,它在GAS中有一个处理程序。 此处理程序导出数据(通过urlfetch)并将一个锚(设置为按钮)附加到ui。 当用户按下该锚点时,该锚点将从我们的服务器打开一个新选项卡。

有没有办法从GAS处理程序直接打开新选项卡(没有用户操作)?

We have a Google Aops Script for Google Sheets to interface with our server.

We need to export the selected data and than to open a new browser tab (from our server).

Currently we have a button in the sidebar, which has a handler in GAS. This handler exports the data (via urlfetch) and appends an anchor (styled as a button) to the ui. This anchor opens a new tab from our server, when it is pressed by the user.

Is there a way to directly open the new tab from the GAS handler (without user action)?

最满意答案

不,您无法从处理程序中打开新选项卡。 仅当用户自愿点击锚点时才会打开选项卡,任何方式都会被Apps脚本团队视为安全问题。

但是,您可以向锚点添加处理程序,并在用户导航到新选项卡时处理单击。 我不确定这对你有用。 如果您可以控制目标服务器,则可以添加微调器或其他内容,让用户等待一段时间,直到Apps脚本后端向您发送数据。

这是使用UiApp和我刚才写的库的实现。

function linkAndHandler() {
  var app = UI.newApp('Link And Handler Test');
  UI.app.add(UI.lockAction(UI.anchor('Google.com', 'https://google.com'), 'linkHandler'));
  SpreadsheetApp.getActive().show(UI.finish());
}

function linkHandler() {
  UI.app.add(UI.label('handler ran'));
}

No, you can't open a new tab from a handler. A tab is only opened if the user willingly clicks on an anchor, any way around that is considered a security issue by the Apps Script team.

But you can add a handler to the anchor and process the click while the user navigates to the new tab. I'm not sure this will work for you though. If you have control of the targeted server, then you can add a spinner or something and have the user wait a little until the Apps Script backend sends you the data.

Here's an implementation using UiApp and a library I wrote a while ago.

function linkAndHandler() {
  var app = UI.newApp('Link And Handler Test');
  UI.app.add(UI.lockAction(UI.anchor('Google.com', 'https://google.com'), 'linkHandler'));
  SpreadsheetApp.getActive().show(UI.finish());
}

function linkHandler() {
  UI.app.add(UI.label('handler ran'));
}

                    
                     
          

更多推荐

本文发布于:2023-08-02 14:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1375784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有一   并在   种方法   脚本   开新

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!