用于打开 URL 的 Google Apps 脚本 [英] Google Apps Script to open a URL
问题描述
有没有办法编写一个谷歌应用程序脚本,以便在运行时,第二个浏览器窗口打开到 www.google.com(或我选择的其他网站)?
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)?
我正在尝试解决我之前的问题:我可以添加一个Google Apps 电子表格消息框中的超链接
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
推荐答案
您可以构建一个小型 UI 来完成这样的工作:
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);
}
如果你想显示"URL,只需像这样更改这一行:
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 (just make a copy to use instead).
UiApp 已于 2014 年 12 月 11 日被 Google 弃用,此方法可能随时失效,需要更新以改用 HTML 服务!
下面是一个使用 html 服务的实现.
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");
}
这篇关于用于打开 URL 的 Google Apps 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!