下面是传递给 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 isOffice.context.requirements.isSetSupported
.
关于javascript - 无法从对话框中的 <script> 访问 Javascript API for Office,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53306844/