0

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
  • 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.
    – toddmo
    Commented Jan 6, 2020 at 16:36

1 Answer 1

2

Here's how to open multiple urls in different new browser tabs:

multiple urls in different 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);
}
2
  • 1
    I tested your code. It works! P.S. Don't forget to mark this answer as accepted. Commented Jan 11, 2020 at 23:09
  • @Rubén, gosh thanks Ruben! That's very nice of you :)
    – toddmo
    Commented Jan 12, 2020 at 15:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.