You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Outlook Add-in链接跳转设置:如何让所有链接默认打开Chrome

解决Outlook Add-in中链接默认在浏览器打开的问题

核心方案:使用Office.js官方API

Office插件提供了专门的Office.context.ui.openBrowser()方法,能强制链接在系统默认浏览器(如Chrome)中打开,完全规避Outlook内嵌窗口的问题,这也是官方推荐的方式。

实现步骤

  1. 修改a标签的点击逻辑
    给所有需要外部打开的链接添加点击事件,阻止默认跳转,调用openBrowser方法:
<!-- 替换原有a标签 -->
<a href="https://rachmar.com" onclick="handleLinkClick(event, 'https://rachmar.com')">https://rachmar.com</a>
<a href="https://app.rachmar.com" onclick="handleLinkClick(event, 'https://app.rachmar.com')">https://app.rachmar.com</a>

<script>
function handleLinkClick(event, targetUrl) {
  // 阻止a标签的默认跳转行为
  event.preventDefault();
  // 调用Office.js API打开浏览器
  Office.context.ui.openBrowser(targetUrl, function(asyncResult) {
    if (asyncResult.status === Office.AsyncResultStatus.Failed) {
      console.error('打开链接出错: ' + asyncResult.error.message);
    }
  });
}
</script>
  1. 确保加载Office.js库
    在你的taskpane.html头部必须包含Office.js的引用,否则无法调用上述API:
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
  1. 配置清单文件的域名权限
    打开插件的manifest.xml,将主域名和子域名添加到<AppDomains>节点中,确保Office.js有权限访问这些域名:
<AppDomains>
  <AppDomain>https://rachmar.com</AppDomain>
  <AppDomain>https://app.rachmar.com</AppDomain>
</AppDomains>

为什么window.open无效?

Outlook插件的任务窗运行在受限的iframe环境中,普通的window.open会被Outlook拦截或强制在内嵌窗口打开,而openBrowser是专门为Office插件设计的API,能绕过这个限制。

内容的提问来源于stack exchange,提问作者R. Mohammad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 17:42:11