I have a row with multiple urls on it. I'd like to open each url in a separate browser tab without having to click on each link. Is this possible in Google Sheets or Google Apps Script?
-
1@Rubén, please see my answer below. It's possible via Google Apps Script HtmlService (indirectly). What you said in your answer here stackoverflow.com/a/29906951/1045881 is technically correct when you said Script itself will not automatically open web pages, but the end effect is possible via the combination of server and client script.– toddmoJan 6, 2020 at 16:36
1 Answer
Here's how to open multiple urls in different new browser tabs:
It creates html script to do the job. Be sure the urls each begin with the protocol (e.g., not just 'www') or google will get confused.
The function takes an array of urls. Those can come from anywhere including getValues()
where you've got multiple urls on a row in a spreadsheet, or anywhere else.
function openTabs(urls) {
if(!Array.isArray(urls))
urls = [urls];
var html =
"<script>" +
urls.map(function(url) {
return "window.open('" + url + "');";
})
.join('') +
"google.script.host.close();" +
"</script>";
var userInterface = HtmlService.createHtmlOutput(html)
.setWidth( 90 )
.setHeight( 1 );
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Opening...');
}
function testOpenTabs() {
var urls = ['http://www.google.com','http://www.stackoverflow.com','http://www.wikipedia.com'];
openTabs(urls);
}
-
1I tested your code. It works! P.S. Don't forget to mark this answer as accepted.– Rubén ♦Jan 11, 2020 at 23:09
-