1
votes

I have a Google Apps Script for Google spreadsheets which opens a secondary browser window (for authentication to an external system).

After the authentication we get a redirect to the webapp part of the script (doGet).

How do I close the browser window from Google Apps Script (so that the user can continue in the spreadsheet)?

2

2 Answers

1
votes

Have you developed your interface using UiApp or HtmlService?

If it's HtmlService, have you tried google.script.host.close()? I'm not sure if it's going to work though. If you test it, please give feedback here. -- edit from feedback on comments, it seems that does not work for standalone scripts, just if it's embeeded on sidebars or dialogs.

If it's UiApp, then it's not possible, see issue 474.

0
votes

I changed the design to solve the issue:

1) I do no longer use a webapp in GAS to wait for some authentications codes. We instead poll (via UrlFetch) our server from the GAS side until the authentication has completed.

2) I now let the authentication window close itself

window.open("","_self","").close();

The code might look tricky, but it works with current browsers. ( The more natural looking window.close() doesn't).