Is there a way to write a google apps script so when ran, a second browser window opens to www.google.com (or another site of my choice)?
I am trying to come up with a work-around to my previous question here: Can I add a hyperlink inside a message box of a Google Apps spreadsheet
Building of off an earlier example, I think there is a cleaner way of doing this. Create an
index.html
file in your project and using Stephen's code from above, just convert it into an HTML doc.Then, in your
Code.gs
script, you can have something like the following,You can build a small UI that does the job like this :
If you want to 'show' the url, just change this line like this :
EDIT : link to a demo spreadsheet in read only because too many people keep writing unwanted things on it... make a copy to use.
EDIT : !! UiApp was depreciated by Google on 11th Dec 2014, this method could break at any time and needs updating to use HTML service instead. !!
EDIT : below is an implementation using html service.
Google Apps Script will not open automatically web pages, but it could be used to display a message with links or buttons that the user could click on them to open the desired web pages.
It's worth to note that UiApp is now deprecated. From Class UiApp - Google Apps Script - Google Developers
The example in the HTML Service linked page is pretty simple,
Code.gs
A customized version of index.html to show two hyperlinks
This function opens a URL without requiring additional user interaction.
This method works by creating a temporary dialog box, so it will not work in contexts where the UI service is not accessible, such as the script editor or a custom G Sheets formula.
The only difference between these two:
is that in the first case the link will display "open" in the dialog box. So far I have found no way to open automatically the link... (see https://developers.google.com/apps-script/class_anchor).
The only other way to open a doc automatically seems to be:
var doc = DocumentApp.openById(foundFile.getId());
but then I'm not sure what should be done with doc! I.e. there is no doc.show()...