You can use the Office dialog API to open dialog boxes in your Office Add-in. See Use the Office dialog API in Office Add-ins for more information.
Code in the dialog box uses the messageParent
function to send a string message to the host page. The string can be a word, sentence, XML blob, stringified JSON, or anything else that can be serialized to a string or cast to a string. To use the messageParent
method, the dialog box must first initialize the Office JavaScript API:
Office.onReady(function() {
// Add any initialization code for your dialog here.
});
// Called when dialog signs in the user.
function userSignedIn() {
Office.context.ui.messageParent(true.toString());
}
The messageParent
function is one of only two Office JS APIs that can be called in the dialog box. The host page must be configured to receive the message. You do this by adding a callback parameter to the original call of displayDialogAsync
. The callback assigns a handler to the DialogMessageReceived
event. For example:
let dialog; // Declare dialog as global for use in later functions.
Office.context.ui.displayDialogAsync('https://www.contoso.com/myDialog.html', {height: 30, width: 20},
function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
}
);
Basically, from your message box instance you can send a message to the host page where you can call a function.