gpt4 book ai didi

excel - Office.js Office.context.ui.messageParent 在 Excel 中不起作用

转载 作者:行者123 更新时间:2023-12-04 22:16:32 27 4
gpt4 key购买 nike

我们有一个托管在 Azure 中的 excel 加载项,其中 Office.context.ui.messageParent API 消息不会在桌面上发送/接收。没有错误,消息只是没有被事件监听器捕获。
我们使用 MFA 的对话框,我们让它在桌面和 Web 本地工作,但是当我们部署到托管在 azure 中的阶段加载项时,这个问题只发生在桌面上。
这有效:

  • 对话网址 (https://localhost:3000/dist/callback.html)
  • 任务 Pane 网址 (https://localhost:3000/dist/taskpane.html)

  • 这不会:
  • 对话网址 ( https://ip-dev-custom-functions.azurewebsites.net/addin/callback.html )
  • 任务 Pane 网址(https://ip-dev-custom-functions.azurewebsites.net/addin/taskpane.html)

  • 令人惊讶的是,DialogEventReceived 被触发,但不是消息 DialogMessageReceived。
    回调.html:
    <!DOCTYPE html>
    <html>

    <head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
    <meta http-equiv="Expires" content="0"/>
    <meta http-equiv="Cache-Control" content="private, no-cache, no-store"/>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="Expires" content="-1"/>
    <title></title>
    <script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>
    </head>

    <body>
    <script>
    if (window.opener)
    window.opener.postMessage({type: 'interstitial', url: document.location.href}, "*");

    Office.initialize = function (reason) {
    console.log("Sending auth complete message through dialog: " + document.location.href);
    Office.context.ui.messageParent(document.location.href);
    }
    </script>
    </body>
    </html>
    taskpane.html 的片段,事件监听器在哪里:
    Office.context.ui.displayDialogAsync(url, {
    height: dim.height,
    width: dim.width,
    promptBeforeOpen: false
    }, async (result) => {
    _loginDialog = result.value;
    _loginDialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
    _loginDialog.addEventHandler(Office.EventType.DialogEventReceived, (ev) => {
    console.log("## EVENT RECEIVED ##", ev);
    });
    });

    function processMessage(arg) {
    console.log("Message received in processMessage: " + JSON.stringify(arg));
    _lastCallback(arg.message);
    _loginDialog?.close();
    _loginDialog = null;
    }
    enter image description here

    最佳答案

    基于 Authenticate and authorize with the Office dialog API ,正确的流程是:
    加载项应在加载项的域中启动对话框中的页面,然后重定向到登录页面,然后再次重定向到与对话框中的第一页具有相同域的另一个页面。
    否则,messageParent API 将不起作用,因为它只信任 displayDialogAsync() API 中使用的页面域。在您的场景中,登录页面(第一次在对话框中启动)和回调页面位于不同的域中,这会导致问题。
    谢谢。

    关于excel - Office.js Office.context.ui.messageParent 在 Excel 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68595740/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com