gpt4 book ai didi

office-js - 对话框 API 的 messageParent 不能与 OWA 一起使用

转载 作者:行者123 更新时间:2023-12-04 21:31:59 37 4
gpt4 key购买 nike

我正在为我的 Outlook 加载项使用 Office Javascript API。我正在运行 Outlook-web-16.01 ( https://outlook.live.com/owa/ )。

我可以通过调用 UI.displayDialogAsync 来弹出对话框.但是调用 UI.messageParent 不会导致 DialogMessageReceived在父页面上触发。我在同一个域上同时运行父级和对话框。

然而,手动关闭对话框会触发 DialogEventReceived在父级上并带有 12006 .

我还注意到该对话框在加载后立即在 JS 控制台上出现此错误,但不确定是否相关:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://outlook.live.com') does not match the recipient window's origin ('MyOrigin').



我正在使用 OfficeDev example from GitHub .

我在父页面上启动对话框的代码复制自 here ,

function dialogCallback(asyncResult) {
if (asyncResult.status == "failed") {

// In addition to general system errors, there are 3 specific errors for
// displayDialogAsync that you can handle individually.
switch (asyncResult.error.code) {
case 12004:
console.log("Domain is not trusted");
break;
case 12005:
console.log("HTTPS is required");
break;
case 12007:
console.log("A dialog is already opened.");
break;
default:
console.log(asyncResult.error.message);
break;
}
}
else {
dialog = asyncResult.value;
/*Messages are sent by developers programatically from the dialog using office.context.ui.messageParent(...)*/
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, messageHandler);

/*Events are sent by the platform in response to user actions or errors. For example, the dialog is closed via the 'x' button*/
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogEventReceived, eventHandler);

console.log(`handler registered`);
}
}

function messageHandler(arg) {
console.log(`handler called`);
dialog.close();
console.log(arg.message);
}

function eventHandler(arg) {

// In addition to general system errors, there are 2 specific errors
// and one event that you can handle individually.
switch (arg.error) {
case 12002:
console.log("Cannot load URL, no such page or bad URL syntax.");
break;
case 12003:
console.log("HTTPS is required.");
break;
case 12006:
// The dialog was closed, typically because the user the pressed X button.
console.log("Dialog closed by user");
break;
default:
console.log("Undefined error in dialog window");
break;
}
}

var dialogUrl = 'MyOrigin/outlook/function-file/dialog.html';
Office.context.ui.displayDialogAsync(dialogUrl, { height: 50, width: 50 }, dialogCallback);

对于对话框 HTML,我所做的与 this code 完全相同。 .

最佳答案

调试 Microsoft Office 库后,我发现了问题。
为了使消息正常工作, list 文件中的 URL 应以 https://为前缀

一旦我更新了我的 list ,一切就开始工作了。

只需确保您在 AppDomains 中的 URL 以 https://为前缀

  <AppDomains>
<AppDomain>https://app.polarcrm.com</AppDomain>
<AppDomain>https://localhost:44321</AppDomain>
</AppDomains>

这是我的实现细节:
https://yaplex.com/blog/office-addin-messageparent-not-working

enter image description here

关于office-js - 对话框 API 的 messageParent 不能与 OWA 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49518618/

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