使用按钮在新窗口中使用Google Appsscript打开网址 [英] Use button to open URL in new window with Google Appsscript

查看:86
本文介绍了使用按钮在新窗口中使用Google Appsscript打开网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为新的Google表格编写应用程序,以将另一个API与表格集成。我需要通过打开一个允许用户登录来授权我的应用程序的新窗口来授权用户。

到目前为止,我发现要做到这一点的唯一方法就是使用简单的超链接。有没有办法通过一个在后端调用函数的按钮来实现这一点?当用户点击一个按钮时,我无法弄清楚任何可以在新窗口中打开链接的功能。



注意:我想这样做是为了与UI保持一致。我需要添加一个授权和取消授权按钮。取消授权按钮只是调用一个功能从用户帐户中删除访问令牌,但授权按钮需要打开一个新的URL以将用户发送到另一个站点进行登录。

解决方案

这是一个使用自动打开边栏的可能解决方案,它看起来像这样:



和下面的代码:

  function onOpen(){
var shUi = SpreadsheetApp.getUi();
var app = UiApp.createApplication()。setTitle('Custom functions');
var panel = app.createVerticalPanel()。add(app.createHTML('请在下面选择一个选项')。setStyleAttribute('padding','10px'));
var grid = app.createGrid(1,2).setWidth('200');
var dHandler = app.createServerHandler('removeAuth');
var b1 = app.createButton(Authorize);
var b2 = app.createButton(De-authorize,dHandler).setTitle('remove authorization');
var link = app.createAnchor('XXXXX','http://www.google.com').setStyleAttributes({'zIndex':'1','position':'fixed','top' :'45','left':'20','color':'transparent'})。setTitle('进入一个新标签');
var G1 = app.createVerticalPanel()。add(b1).add(link);
grid.setWidget(0,0,G1).setWidget(0,1,b2);
app.add(panel).add(grid)
shUi.showSidebar(app);


函数removeAuth(){
//一些代码
}


I am writing an application for the new Google Sheets to integrate another API with Sheets. I need to authorize the user by opening a new window allowing the user to login to authorize my app.

So far the only way I have found to do this is with a simple hyperlink. Is there a way to do this with a button that calls a function on the backend? I can't figure out anything that works to open a link in a new window when a user clicks on a button.

NOTE: I want to do this to be consistent with the UI. I need to add an "authorize" and a "deauthorize" button. The deauthorize button just calls a function to delete the access token from the users account, but the authorize button needs to open a new URL to send the user to another site to login.

解决方案

Here is a possible solution using an auto open sidebar, it looks like this :

and the code below :

function onOpen() {
  var shUi = SpreadsheetApp.getUi();
  var app = UiApp.createApplication().setTitle('Custom functions');
  var panel = app.createVerticalPanel().add(app.createHTML('please select an option below').setStyleAttribute('padding','10px'));
  var grid = app.createGrid(1,2).setWidth('200');
  var dHandler = app.createServerHandler('removeAuth');
  var b1 = app.createButton("Authorize");
  var b2 = app.createButton("De-authorize",dHandler).setTitle('remove authorization');
  var link = app.createAnchor('XXXXX','http://www.google.com').setStyleAttributes({'zIndex':'1' , 'position':'fixed' , 'top':'45' , 'left':'20', 'color':'transparent' }).setTitle('proceed in a new tab');
  var G1 = app.createVerticalPanel().add(b1).add(link);
  grid.setWidget(0,0,G1).setWidget(0,1,b2);
  app.add(panel).add(grid)
  shUi.showSidebar(app);
}

function removeAuth(){
  // some code
}

这篇关于使用按钮在新窗口中使用Google Appsscript打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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