1

What I am trying to do is to open several browser tabs, the url will be coming from the cells of a spreadsheet.

I found a good tutorial for that. Apps Script: Open a new tab with an image - YouTube

I reproduced his code and now I am trying to make a loop, but the loop take only the last element of the list.

The problem must be simple, it must be the way I write my loop but I cant find it.

here is the code.

function openTab2() {
  var selection = SpreadsheetApp.getActiveSheet();
  var data = selection.getDataRange().getValues();
  for (var i = 0; i < data.length; i++) {
  var html= "<script> window.open( '" +(data[i][0]) + "');google.script.host.close(); </script>";
  var userInterface = HtmlService.createHtmlOutput (html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'open Tab')
}
Kara
  • 6,115
  • 16
  • 50
  • 57
Tsurubaso
  • 25
  • 8
  • Apart from a missing "}" at the end of the script, it ran fine for me opening tabs for urls entered in column A. I did have to respond to a popup warning one time. – Ed Nelson Jun 07 '18 at 17:32
  • Thanks to have helped me. I add the missing }. Then if if it work find in your computer, it must be some pop up limitation on my chrome. Thanks and have a good day. – Tsurubaso Jun 08 '18 at 01:32
  • function myFunction() { var selection = SpreadsheetApp.getActiveSheet(); var data = selection.getDataRange().getValues(); for (var i = 0; i < data.length; i++) { var html= ""; var userInterface = HtmlService.createHtmlOutput (html); SpreadsheetApp.getUi().showModalDialog(userInterface, 'open Tab') } } – Tsurubaso Jun 09 '18 at 05:47
  • OK," enter" send immediately your comment, other think learned! I modified the code, and i was able to open tab using folder ID in a spreadsheet, but Just 2, the list had 10 or so folders ids. I don't now what was wrong, – Tsurubaso Jun 09 '18 at 05:52
  • Maybe some privacy setting of firefox under popup, I would continue to check and report. Meanwhile any help is welcome. – Tsurubaso Jun 09 '18 at 06:03
  • [ref 1](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript) – Tsurubaso Jun 09 '18 at 06:36
  • `function myFunction() { var selection = SpreadsheetApp.getActiveSheet(); var data = selection.getDataRange().getValues(); for (var i = 0; i < data.length; i++) { var html= ""; Logger.log('la valeur de i est %s', i); var userInterface = HtmlService.createHtmlOutput (html); SpreadsheetApp.getUi().showModalDialog(userInterface, 'open Tab') } } ` – Tsurubaso Jun 09 '18 at 08:31

1 Answers1

0

I finally found the solution, it was obvious, "give time to your old CPU", a long day of try and error. I hope this solution will help your project.

function myFunction() {
  var selection = SpreadsheetApp.getActiveSheet();
  var data = selection.getDataRange().getValues();
  for (var i = 0; i < data.length; i++) {

  var html= "<script> window.open( '"+"https://drive.google.com/drive/u/0/folders/"+(data[i][0])+"', '_blank');window.focus; google.script.host.close(); </script>";
  Logger.log('la valeur de i est  %s', i);
  var userInterface = HtmlService.createHtmlOutput (html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, 'open Tab');
  Utilities.sleep(8000);
}
}
Tsurubaso
  • 25
  • 8