Word Online中的displayDialogAsync不记录与Word Online不同的关闭操作/损坏行为到Word for Mac

时间:2018-05-29 17:02:37

标签: javascript office-js

当我在Word Online中关闭对话框时,我在控制台中收到以下消息:

Unknown conversation Id.

而不是获得我可以处理的代码,我只是得到了......

(macOS / Chrome版本66.0.3359.181(官方版)(64位))

在Word for Mac上运行的相同代码(从localhost和sideloaded manifest运行)16.13.1(180523) - 慢速构建 - 导致对话窗口无法正常运行...关闭后,他们不会#39 ;触发我可以使用的代码,Javascript似乎不会在其中运行。当我尝试检查对话框时,窗口会出现狂躁的闪烁,控制台无法打开。

整体感觉displayDialogAsync API有问题。

以下是一个示例对话框创建代码段:

$('.integrateQuotes').click(function(){
    console.log('Clicking quote machine choice...');
    var dialogUrl = 'https://localhost/AnnotateX/qWord/modules/integratequotes.html';
    var dialog = null;   //  dialogwindow object
    Office.context.ui.displayDialogAsync(dialogUrl, {height: 80, width: 80, displayInIframe: true}, function (asyncResult){
        dialog = asyncResult.value;
        error = asyncResult.error;
        status = asyncResult.status;
        console.log('Result from dialog window...error: ') +  + console.log(' and status: ') + console.log(status) + console.log(dialog);
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
    });
  });
  self.location.href = '#writingDiv';

and processMessage:

function processMessage(arg) {
    // var messageFromDialog = JSON.parse(arg.message);
    // showUserName(messageFromDialog.name);
    console.log('processing message from dialog: ') + console.log(arg);

    // switch (arg.error) {
    //      case 12002:
    //          console.log("The dialog box has been directed to a page that it cannot find or load, or the URL syntax is invalid.");
    //          break;
    //      case 12003:
    //          console.log("The dialog box has been directed to a URL with the HTTP protocol. HTTPS is required.");            break;
    //      case 12006:
    //          console.log("Dialog closed.");
    //          break;
    //      default:
    //          console.log("Unknown error in dialog box.");
    //          break;
    //   }

    // dialog.close();
    if (arg.message === 'easyBib'){
      //Now open URL
      var win = window.open('http://www.easybib.com/cite/results?source=website&provider=&cite-style=mla7&query=' + localStorage.easyBib);
      console.log("Sending to easyBib: " + localStorage.easyBib);
      if (win) {
          //Browser has allowed it to be opened
          win.focus();
      } else {
          //Browser has blocked it
          alert('Please allow popups for this website');
      }
    } else {
      dialog.close();
      self.location.href = '#writingDiv';
    }
    // self.location.href = 'qResearch.html';
    // window.location.replace("/qResearch.html");
    // window.location.href = "/newPage.html";
}

我现在要尝试使用Windows ...但是

1 个答案:

答案 0 :(得分:1)

要处理用户关闭对话框的事件,您需要DialogEventReceived事件的处理程序,而不是DialogMessageReceived。还有以下内容:Using a Dialog with Office Add-ins