Apps Script: Open a new tab with an image
Why Stack Overflow recommends it
Stack Overflow users link it as the source of the window.open plus showModalDialog trick for opening a URL in a new tab from Apps Script.
Recommended by 1 people across 1 different months, 2018 to 2019.
What it is
A short screencast tutorial by Jordan Rhea showing how to use Google Apps Script to open a new browser tab from a Google Sheet. It builds a small HtmlService dialog that runs window.open and then closes itself.
What people said
Recommends AMolina · 2019-09 · Stack Overflow · on “How to open a sheet by script from a spreadsheet?”
If "Titito" is the name of the actual file, then SpreadsheetApp.open(Titito) is not the way; sa you can see in the documentation [LINK] , that uses file objects. In order to get it through the name, you will need to instead use DriveApp ( Documentation here [LINK] ). With it you can get the files in your Drive and get the one you're looking for, the code for that looks like this: function fn(){ var files = DriveApp.getFiles(); var file; while (files.hasNext()){ file = files.next(); if (file.getName() == "Titito") break; } var ss = SpreadsheetApp.open(file).getUrl(); // rest of your code... } UPDATE OP needed a way to open the actual Spreadsheet through the script, after following the instruc
Cites ScottGutman · 2018-04 · Stack Overflow · on “Open Google Sheet on Client side using Google Apps Script”
You could use this code to open a new sheet: function openNewSheet() { var spreadsheetId = YOUR_ID_HERE; var url = " [LINK] "+spreadsheetId; var html = "<script>window.open('" + url + "');google.script.host.close();</script>"; var userInterface = HtmlService.createHtmlOutput(html); SpreadsheetApp.getUi().showModalDialog(userInterface, "Open Sheet"); } I got this from this post: [this video]
Cites ScottGutman · 2018-04 · Stack Overflow · on “Google Apps Script to Open copy of Google Sheet in new window”
You could capture the google file object in the makeCopy() with gFile = DriveApp.getFileById(sheet.getId()).makeCopy(fileName, destFolder); return gFile; then add this function to open a new sheet: function openNewSheet(gFile) { var spreadsheetId = gFile.getId(); var url = " [LINK] "+spreadsheetId; //SpreadsheetApp.getUi().alert('url is ' + url); var html = "<script>window.open('" + url + "');google.script.host.close();</script>"; var userInterface = HtmlService.createHtmlOutput(html); SpreadsheetApp.getUi().showModalDialog(userInterface, "Open Sheet"); } Finally you can add openNewSheet() to the end of onOpen() Some credit goes to this video: [this video]
Cites Tsurubaso · 2018-06 · Stack Overflow · on “Opentab from Url on a spreatsheet”
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 [this video] 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 = HtmlSe
Cites Bramako · 2018-11 · Stack Overflow · on “Open link in a window using script (Google Sheet)”
I was looking for the same thing and found the solution below. In this case it opens the link in the cell, that is selected when you press the button. You could however just change the "selection" part and insert a url directly. function openTab() { var selection = SpreadsheetApp.getActiveSheet().getActiveCell().getValue(); var html = "<script>window.open('" + selection + "');google.script.host.close();</script>"; var userInterface = HtmlService.createHtmlOutput(html); SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Tab'); } They seem to have tightened security however, when I try this in Chrome, the new window is blocked by the built-in pop-up blocker. And Firefox doesn't even s