Search code examples
javascriptgoogle-sheetsgoogle-apps-scriptmodal-dialog

Capture onClose event for Spreadsheet App Modal Dialog in Google Apps Script


I want to do something when the Modal Dialog (opened using showModalDialog()) is closed from the Spreadsheet App.

However I cannot find the reference of such event, in the API documents provided by Google. I found how to capture this event in a Alert Box, and by using this piece of code I can capture how the user closed the Alert Box, but I cannot use this in a Modal Dialog or a Modeless Dialog.

Is there a way to do this? Please kindly answer if you do.


Solution

  • This is not possible. And you should write your script in a way that this does not matter. For example, by showing a big action button in the dialog, making it clear to the user that he must click there for the script to continue.

    But if you really want to make this happen, I guess you could use an HtmlService dialog that make regular async calls to the backend and each call waits for the next one before quitting, then if the "next" call does not get in time, it can assume the dialog got closed and execute your close procedure instead of simply quitting.