Office Dialog API send message to child dialog

旧时模样 提交于 2019-12-23 19:12:04

问题


We would like to use the Dialog API for some extra operations which are better suited to a larger work area. We already have the ability via the API to message the parent from the dialog (Office.context.ui.messageParent), however we would also like the ability to directly message the dialog, like a sendMessage function, for example:

var dialog;
Office.context.ui.displayDialogAsync('https://myDomain/myDialog.html', function (asyncResult) {
    if (asyncResult.status === "failed") { 
        showNotification(asynceResult.error.code = ": " + asyncResult.error.message); 
    } else {
        dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
        dialog.sendMessage({ /* my payload */ }); //???
    }
}); 

There are a couple of options to pass data from the parent to the child:

  1. query string: displayDialogAsync(myUrl + "?myMessage=...", function...)
  2. localStorage (if on the same domain): localStorage.setItem("DIALOG_MESSAGE", myMessage)

However, both of these can only really be used on initialization of the dialog, they do not provide a nice way to do asynchronous messaging.


回答1:


That is a popular request (and a good idea), but it is not supported yet. Please go to Office Dev User Voice and vote up the "Improve Custom Dialog" suggestion there or create a new suggestion of your own.




回答2:


You can use this in parrent before usedisplayDialog:

localStorage.setItem("clientID", "15963ac5-314f-4d9b-b5a1-ccb2f1aea248");

And then in your JavaScript file:

var clientID = localStorage.getItem("clientID");


来源:https://stackoverflow.com/questions/42817868/office-dialog-api-send-message-to-child-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!