Office Outlook 加载项在初始化期间出错

Error in Office Outlook Add-in during Initiallzation

我在桌面客户端加载 Outlook 加载项时遇到这样的错误:

SCRIPT5022: Office.js has not been fully loaded yet. Please try again later or make sure to add your initialization code on the Office.initialize function.

我的初始化代码如下所示:

Office.initialize = function (reason) {
    app.initialize();

    // set adal.js b2c authentication
    setAuthContext();

    // handle any window callback redirections
    authContext.handleWindowCallback();

    checkUser();
    setListeners();
};

我用 Office.js 的初始化函数尝试了不同的变体,但我一遍又一遍地得到同样的错误。在 Outlook Online 中使用相同的 Outlook 加载项不会发生这种情况。

我的 Office 应用程序初始化有问题吗?

我认为您需要使用 $(document).readywindow.onload 然后设置您的代码。

来自documentation

If you are using additional JavaScript frameworks that include their own initialization handler or tests, these should be placed within the Office.initialize event. For example, JQuery's $(document).ready()

代码:

Office.initialize = function () {
// Office is ready
$(document).ready(function () {        
    // The document is ready insert your code here

});
};