Edit

Share via


Office.InitializationReason enum

Specifies whether the add-in was just inserted or was already contained in the document.

Remarks

Examples

// You can use the value of the InitializationEnumeration to implement different logic for
// when the add-in is first inserted versus when it is already part of the document.
// The following example shows some simple logic that uses the value of the reason parameter
// to display how the task pane or content add-in was initialized.
Office.initialize = function (reason) {
    // Checks for the DOM to load using the jQuery ready method.
    $(document).ready(function () {
        // After the DOM is loaded, code specific to the add-in can run.
        // Display initialization reason.
        if (reason === Office.InitializationReason.Inserted) {
            write("The add-in was just inserted.");
        }

        if (reason === Office.InitializationReason.DocumentOpened) {
            write("The add-in is already part of the document.");
        }
    });
}

// Function that writes to a div with id='message' on the page.
function write(message) {
    document.getElementById('message').innerText += message;
}

Fields

DocumentOpened

The add-in is already part of the document that was opened.

Inserted

The add-in was just inserted into the document.