Google Apps脚本打开一个URL [英] Google Apps Script to open a URL

查看:96
本文介绍了Google Apps脚本打开一个URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法编写一个谷歌应用程序脚本,所以当运行时,第二个浏览器窗口打开www.google.com(或我选择的另一个网站)?



<我试图想出一个解决我以前的问题在这里:
解决方案

您可以构建一个小型用户界面来执行此项任务:

 函数test(){
showURL(http://www.google.com)
}
//
function showURL(href){
var app = UiApp.createApplication()自动调用setHeight(50).setWidth(200)。
app.setTitle(显示网址);
var link = app.createAnchor('open',href).setId(link);
app.add(link);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}

如果您想'显示'网址,只需更改此行:

  var link = app.createAnchor(href,href).setId(link); 

编辑:链接至中的演示电子表格只读,因为太多人不断在其上写入不需要的东西......制作副本以供使用 p>

编辑:!! UiApp在2014年12月11日被Google贬值,此方法随时可能中断,需要更新才能使用HTML服务。 !



编辑:
以下是使用html服务的实现。

  function testNew(){
showAnchor('Stackoverflow','http://stackoverflow.com/questions/tagged/google-apps-script');
}

函数showAnchor(name,url){
var html ='< html>< body>< a href ='+ url +'target = blankonclick =google.script.host.close()>'+ name +'< / a>< / body>< / html>';
var ui = HtmlService.createHtmlOutput(html)
SpreadsheetApp.getUi()。showModelessDialog(ui,demo);
}


Is there a way to write a google apps script so when ran, a second browser window opens to www.google.com (or another site of my choice)?

I am trying to come up with a work-around to my previous question here: Can I add a hyperlink inside a message box of a Google Apps spreadsheet

解决方案

You can build a small UI that does the job like this :

function test(){
showURL("http://www.google.com")
}
//
function showURL(href){
  var app = UiApp.createApplication().setHeight(50).setWidth(200);
  app.setTitle("Show URL");
  var link = app.createAnchor('open ', href).setId("link");
  app.add(link);  
  var doc = SpreadsheetApp.getActive();
  doc.show(app);
  }

If you want to 'show' the url, just change this line like this :

  var link = app.createAnchor(href, href).setId("link");

EDIT : link to a demo spreadsheet in read only because too many people keep writing unwanted things on it... make a copy to use.

EDIT : !! UiApp was depreciated by Google on 11th Dec 2014, this method could break at any time and needs updating to use HTML service instead. !!

EDIT : below is an implementation using html service.

function testNew(){
  showAnchor('Stackoverflow','http://stackoverflow.com/questions/tagged/google-apps-script');
}

function showAnchor(name,url) {
  var html = '<html><body><a href="'+url+'" target="blank" onclick="google.script.host.close()">'+name+'</a></body></html>';
  var ui = HtmlService.createHtmlOutput(html)
  SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
}

这篇关于Google Apps脚本打开一个URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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