Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

office-runtime package

Interfaces

OfficeRuntime.ApiInformation

Interface that contains methods for checking API requirement-set support.

OfficeRuntime.Auth

Interface that contains authorization related APIs.

OfficeRuntime.AuthOptions

Provides options for the user experience when Office obtains an access token to the add-in from AAD v. 2.0 with the getAccessToken method.

OfficeRuntime.Dialog

Object representing the dialog box.

OfficeRuntime.DisplayWebDialogOptions

Provides display options and actions a dialog box may take.

OfficeRuntime.Storage

Asynchronous, global, and persistent key-value storage.

Functions

OfficeRuntime.displayWebDialog(url, options)

Function that enables a pop up web dialog box.

Function Details

OfficeRuntime.displayWebDialog(url, options)

Function that enables a pop up web dialog box.

export function displayWebDialog(url: string, options?: DisplayWebDialogOptions): Promise<Dialog>;

Parameters

url

string

Must be a string.

options
OfficeRuntime.DisplayWebDialogOptions

Optional parameter. Must be of type DisplayWebDialogOptions.

Returns

Remarks

API set: CustomFunctionsRuntime 1.1

Examples

/**
 * Opens an authentication dialog from a custom function.
 * @customfunction AUTH.LOGIN
 * @returns A promise that resolves to the authentication result.
 */
async function authLogin(): Promise<string> {
 const dialogUrl = "https://your-addin-domain.com/auth-dialog.html";

 return new Promise((resolve, reject) => {
 OfficeRuntime.displayWebDialog(dialogUrl, {
 height: "50%",
 width: "40%",

 onMessage: (message: string, dialog?: OfficeRuntime.Dialog) => {
 // Handle messages sent from the dialog via window.opener.postMessage().
 const data = JSON.parse(message);

 if (data.type === "auth-success") {
 // Process the authentication token
 dialog?.close();
 resolve(`Signed in as ${data.username}`);
 } else if (data.type === "auth-error") {
 dialog?.close();
 reject(new Error(data.errorMessage));
 }
 },

 onClose: () => {
 // Handle the user closing the dialog.
 resolve("Dialog closed");
 },

 onRuntimeError: (error: Error, dialog?: OfficeRuntime.Dialog) => {
 // Handle runtime errors from the dialog.
 dialog?.close();
 reject(error);
 },
 }).catch((error) => {
 reject(new Error(`Failed to open dialog: ${error.message}`));
 });
 });
}

Feedback

Was this page helpful?