Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Office.initialize event (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

Occurs when the runtime environment is loaded and the app is ready to start interacting with the application and hosted document.

Last modified: February 26, 2014

Office.initialize = function (reason) {/* initialization code */}

The reason parameter of the initialize event listener function returns an InitializationReason enumeration value that specifies how initialization occurred. A task pane or content app can be initialized in two ways:

  • The user just inserted it from Recently Used Apps section of the App drop-down list on the Insert tab of the ribbon in the Office host application, or from Insert app dialog box.

  • The user opened a document that already contains the app.

Note Note

The reason parameter of the initialize event listener function only returns an InitializationReason enumeration value for task pane and content apps. It does not return a value for mail apps.

Added support for initializing content apps for Access.

You can use the value of the InitializationEnumeration to implement different logic for when the app 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 app was initialized.

Office.initialize = function (reason) {
    // Checks for the DOM to load using the jQuery ready function.
    $(document).ready(function () {
    // After the DOM is loaded, app-specific code can run.
    // Display initialization reason.
    if (reason == "inserted")
    write("The app was just inserted.");

    if (reason == "documentOpened")
    write("The app 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; 

App types

Content apps, Mail apps, Task pane apps

Supported clients

Access app for SharePoint, Excel 2013, Excel 2013 SP1, Excel Online, Outlook 2013, Outlook 2013 SP1, Outlook Web App, OWA for Devices, PowerPoint 2013, PowerPoint 2013 SP1, Project 2013, Project 2013 SP1, Word 2013, and Word 2013 SP1





Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.