如何在Google Apps脚本中打开URL? [英] How to open a URL in google apps script?

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

问题描述

[ https://docs.google.com/spreadsheets/d/1owEwaLhddXvSfI11AA7ZWmuQh4oeKoVSZkiu9LSlRLU/edit?usp = sharing ]

这是我的工作表,我在其中手动填写第一行的开始时间.我是第一次手动打开链接,并将对可购买的"列的判断标记为是/否.一旦我做出判断,我希望结束时间"列自动填充,并且希望下一行"URL"列中的链接自动打开并重复相同的系列.我需要在Google电子表格上执行此任务时,是否可以通过应用脚本执行该操作?

This is my sheet in which i fill the start time for first row manually. I open the link manually for the first time and mark my judgement for "Purchasable" Column as Y/N. As soon as i mark my judgement i want the "end time" column to fill automatically and the link in the "URL" column of the next row to open up automatically and repeat the same series. Is it possible by app script as I need to perform this task on google spreadsheet.

if(r.getColumn()==4){
var endCell=r.offset(0,4);
if(endCell.getValue()==='')
var date=Utilities.formatDate(new Date(),timezone,timestamp_format);
endCell.setValue(date);
var startCell=r.offset(1,-1);
startCell.setValue(date);

现在,当我填写可购买的列时,这可以填满示例的开始时间和结束时间,但是我无法弄清楚如何在不单击它的情况下打开下一个URL?

Now this could fill up the start and end time for a sample when i fill up the purchasable Column but I cant figure out how to open the next URL without clicking on it ??

推荐答案

正如Sandy所说,您不能直接从服务器端Apps脚本代码中打开新的浏览器选项卡或浏览器窗口." 据我所知,唯一的解决方案是打开一个对话框,该对话框将自动打开URL.但是,在打开URL之前,您将在电子表格UI中看到对话框的弹出窗口.

As Sandy said, "You can not directly open a new browser tab or browser window from server side Apps Script code." The only solution to my knowledge is to open a dialog box which in turn automate the opening of the URL. But you will see the popup of the dialog box in the spreadsheet UI until the URL is opened.

code.gs

function open_dialog()
{
    var temp_dialog = HtmlService.createHtmlOutputFromFile("temp_dialog").setTitle("everw");
    SpreadsheetApp.getUi().showModalDialog(temp_dialog,"Name");
}

temp_dialog.html

temp_dialog.html

<html>
  <a href="Replace_the_url" id="link" target="_blank" ></a> 
</html>
<script>
  document.getElementById("link").click();
  google.script.host.close();
</script>

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

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