Google Sheets – Open Multiple URLs in New Tabs with Single Click

google sheetsgoogle-apps-script

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?

Best Answer

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);
}