我创建了一个 Outlook 加载项。该插件的目的是调用在线托管的 html 页面上的 java 脚本函数。我遇到的问题是,在 Outlook 桌面上,该加载项工作正常。但在 Outlook new 和 web 上,我收到的错误消息如下:
“很抱歉,我们无法访问`myAddin`。请确保您有网络连接。如果问题仍然存在,请稍后重试。
这是我的“操作按钮”代码:
<DesktopFormFactor>
<FunctionFile resid="Commands.Url"/>
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="GroupLabel"/>
<Control xsi:type="Button" id="ActionButton">
<Label resid="ActionButton.Label"/>
<Supertip>
<Title resid="ActionButton.Label"/>
<Description resid="ActionButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>openNewTab</FunctionName>
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
我没有尝试太多,因为我不明白问题出在哪里。
您遇到的问题可能与 Outlook 桌面版和 Outlook Web 处理网络请求的方式以及它们执行的安全策略的差异有关。以下是排查和解决此问题的一些步骤和建议:
以下是如何在函数文件中定义和使用 openNewTab 函数的示例:
您的函数文件(functions.js)
// This condition is for checking for office host type
Office.onReady(function(info) {
if (info.host === Office.HostType.Outlook) {
// Office is ready
}
});
function openNewTab(event) {
// Ensure the URL is correct and accessible
const url = "https://yourdomain.com/yourpage.html";
// Open the URL in a new tab
window.open(url, "_blank");
// Complete the event
event.completed();
}
清单文件(manifest.xml) 确保在清单中正确指定 FunctionFile:
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
<Hosts>
<Host xsi:type="MailHost">
<DesktopFormFactor>
<FunctionFile resid="Commands.Url"/>
<ExtensionPoint xsi:type="MessageReadCommandSurface">
<OfficeTab id="TabDefault">
<Group id="msgReadGroup">
<Label resid="GroupLabel"/>
<Control xsi:type="Button" id="ActionButton">
<Label resid="ActionButton.Label"/>
<Supertip>
<Title resid="ActionButton.Label"/>
<Description resid="ActionButton.Tooltip"/>
</Supertip>
<Icon>
<bt:Image size="16" resid="Icon.16x16"/>
<bt:Image size="32" resid="Icon.32x32"/>
<bt:Image size="80" resid="Icon.80x80"/>
</Icon>
<Action xsi:type="ExecuteFunction">
<FunctionName>openNewTab</FunctionName>
</Action>
</Control>
</Group>
</OfficeTab>
</ExtensionPoint>
</DesktopFormFactor>
</Host>
</Hosts>
</VersionOverrides>
请遵循这些说明。