"Object doesn't support property or method 'messageParent'" 在 Office js 中登录重定向后
"Object doesn't support property or method 'messageParent'" After login redirect in Office js
我试图打开一个对话框以输入登录凭据,但在从登录权限重定向回来后,我无法再向对话框 parent 发送消息 window 返回授权代码或令牌。如果我不重定向离开该页面,我可以向 parent 发回消息,否则我会在标题中收到错误消息。如何使用对话框中的信息向 parent(在本例中为任务窗格)window 发送消息?
下面是我必须打开和处理对话框的代码 window:
var dialog;
function authenticate() {
hideAll();
Office.context.ui.displayDialogAsync('mydomain/Login',
{ height: 50, width: 25 }, dialogCallback);
}
function dialogCallback(asyncResult) {
if (asyncResult.status === 'failed') {
console.log(asyncResult.error.message);
} else {
dialog = asyncResult.value;
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.
DialogMessageReceived, messageHandler);
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.
DialogEventReceived, eventHandler);
}
}
function messageHandler(arg) {
showAll();
console.log(arg);
dialog.close();
}
function eventHandler(arg) {
showAll();
console.log(arg);
}
这是处理我的登录屏幕的代码:
Office.initialize = function (reason) {
$(document)
.ready(function () {
var code = $('#code').text();
if (code !== '') {
console.log(code);
Office.context.ui.messageParent(code);
} else {
console.log('No code received from auth server');
}
});
};
通过确保我首先登陆我的域上的页面,问题已解决。我最初指向一个从我的域重定向的控制器,但尚未返回页面。
对我来说这是一个不同的问题:我传递给 displayDialogAsync
的 url 已经包含一个 _host_Info
查询参数,它似乎决定 office.js 是否是否是对话(因此暴露 messageParent
m
方法)。
更多信息在此 Github Issue
我试图打开一个对话框以输入登录凭据,但在从登录权限重定向回来后,我无法再向对话框 parent 发送消息 window 返回授权代码或令牌。如果我不重定向离开该页面,我可以向 parent 发回消息,否则我会在标题中收到错误消息。如何使用对话框中的信息向 parent(在本例中为任务窗格)window 发送消息?
下面是我必须打开和处理对话框的代码 window:
var dialog;
function authenticate() {
hideAll();
Office.context.ui.displayDialogAsync('mydomain/Login',
{ height: 50, width: 25 }, dialogCallback);
}
function dialogCallback(asyncResult) {
if (asyncResult.status === 'failed') {
console.log(asyncResult.error.message);
} else {
dialog = asyncResult.value;
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.
DialogMessageReceived, messageHandler);
dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.
DialogEventReceived, eventHandler);
}
}
function messageHandler(arg) {
showAll();
console.log(arg);
dialog.close();
}
function eventHandler(arg) {
showAll();
console.log(arg);
}
这是处理我的登录屏幕的代码:
Office.initialize = function (reason) {
$(document)
.ready(function () {
var code = $('#code').text();
if (code !== '') {
console.log(code);
Office.context.ui.messageParent(code);
} else {
console.log('No code received from auth server');
}
});
};
通过确保我首先登陆我的域上的页面,问题已解决。我最初指向一个从我的域重定向的控制器,但尚未返回页面。
对我来说这是一个不同的问题:我传递给 displayDialogAsync
的 url 已经包含一个 _host_Info
查询参数,它似乎决定 office.js 是否是否是对话(因此暴露 messageParent
m
方法)。
更多信息在此 Github Issue