我对代码并不熟悉,我只是想为我的团队尝试一下。我所拥有的只是一个简单的代码,每次打开我们的Google电子表格时都会弹出一条警告信息(带OK按钮)。我想要发生的是当我们点击“确定”时,它将在新标签中打开一个链接。这是我的“脚本编辑器”代码:
function onOpen() {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var ui = SpreadsheetApp.getUi().alert('Welcome to HAVENLY Offshore Team Workspace! Check out our CONFLUENCE updates today!');
}
请帮助我在这里实现我的最终目标,我一直在努力寻找解决方案。提前谢谢!
答案 0 :(得分:1)
如果您使用自定义对话框而不是alert
,则可以执行此操作。通过允许您定义自己的html,自定义对话框功能更强大。只需在附加到工作表的脚本中创建以下文件。
<强> Code.gs 强>
function onOpen() {
openWelcomeDialog();
}
function openWelcomeDialog() {
// get the html from the file called "Pages.html"
var html = HtmlService.createHtmlOutputFromFile('Pages');
// open the dialog
SpreadsheetApp.getUi()
.showModelessDialog(html, "Welcome to HAVENLY Offshore Team Workspace!")
}
<强> Pages.html 强>
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<!-- target="_blank" directs the link to a new blank tab -->
<a target="_blank" href="http://stackoverflow.com/questions/17711146/how-to-open-link-in-new-tab-on-html">
Check out our CONFLUENCE updates today!
</a>
</body>
</html>
<强>更新强>
当用户点击带有onclick
事件处理程序的链接时,您也可以关闭对话框:
<a onclick="google.script.host.close()" target="_blank" href="||url||">
Check out our CONFLUENCE updates today!
</a>