Skip to content

Instantly share code, notes, and snippets.

Last active July 27, 2017 21:26
What would you like to do?
Workaround to closing dialogs so you can quickly open another
* Closes the currently open dialog asynchronously.
* This has an ugly workaround which is to try to set a new
* event handler on the dialog until it fails. When it failed
* we know the original dialog object was destroyed and we
* can then proceed. The issue we are working around is that
* if you call two dialogs back to back, the second one will
* likely not open at all.
* @param {Office.context.ui.dialog} dialog The dialog to be closed
* @param {function()} asyncResult The callback when close is complete
function dialogCloseAsync(dialog, asyncResult){
// issue the close
// and then try to add a handler
// when that fails it is closed
setTimeout(function() {
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function() {});
dialogCloseAsync(dialog, asyncResult);
} catch(e) {
asyncResult(); // done - closed
}, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment