javascript - 无法从对话框中的 <script> 访问 Javascript API for Office

标签 javascript office-js office-ui-fabric

下面是传递给 displayDialogAsync 的 HTML 文件

<!DOCTYPE html>
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
4  See LICENSE in the project root for license information -->
<html>

<head>
  <title></title>
  <meta charset="utf-8" />
  <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
  <script type="text/javascript" src="Scripts/jquery-3.3.1.min.js"></script>

  <!-- For the Office UI Fabric, go to http://aka.ms/office-ui-fabric to learn more. -->
  <link rel="stylesheet" href="Content/fabric.min.css">
  <link rel="stylesheet" href="Content/fabric.components.min.css">
  <script>
    Office.initialize = function(reason) {


      write();


    }

    function write() {

      // If I uncomment the line below, the text in the dialog box will NOT be updated            
      //var email = Office.context.mailbox.item.sender.emailAddress;

      $("#firstName").text("John");
      $("#lastName").text("Doe");
      $("#gender").text("Male");
      $("#knownas").text("John Doe");
      $("#citizenship").text("Antarctica");
      $("#language").text("Esperanto");
    }
  </script>
</head>

<body>

  <div class="ms-Gridc ms-font-xxl ms-fontColor-neutralSecondary ms-fontWeight-semilight">
    <div class="ms-Grid-row">
      <div class="ms-Grid-col"><span id="firstName"></span></div>
      <div class="ms-Grid-col"><span id="lastName"></span></div>
      <div class="ms-Grid-col"><span id="gender"></span></div>
    </div>
    <div class="ms-Grid-row">
      <div class="ms-Grid-col"><span id="knownas"></span></div>
      <div class="ms-Grid-col"><span id="citizenship"></span></div>
      <div class="ms-Grid-col"><span id="language"></span></div>
    </div>
  </div>
</body>

</html>

每当我尝试使用 Office JavaScript API 中的任何内容时,我都会注意到我的对话框显示为空白。

在示例中,我所做的只是为变量分配一个值,其余代码将停止工作。控制台上没有出现错误消息。

最佳答案

这是预期的行为。我在 documentation for the dialog 中找到了以下内容:

The messageParent function is one of only two Office APIs that can be called in the dialog box. The other is Office.context.requirements.isSetSupported.

关于javascript - 无法从对话框中的 &lt;script&gt; 访问 Javascript API for Office,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53306844/

相关文章:

javascript - 常规推送和 Array.prototype.push.apply 之间有什么区别

javascript - 如何使用javascript将本地word docx文件上传到服务器上

javascript - Outlook AddIn GetAsync 成功但不返回任何内容

javascript - 如何在 React Outlook-Web-addin 中安全更新 Office-js-依赖项?

javascript - 从数字转换为字符串在 Javascript 中给出奇怪的数字

javascript - 正则表达式至少 8 个字符,一个大写字母和至少一个数字不在字符串的开头和结尾

javascript - 两个类之间的状态

reactjs - 类型 '{ children: string; }' 与类型 'IntrinsicAttributes & IModalProps' 没有共同属性

office-ui-fabric - 如何在 office-ui-fabric 中隐藏 GroupedList header 中的计数?

reactjs - Office UI Fabric - 如何将 css 样式应用到现有组件