检测是否在 outlook-add-in 中打开了 Web 应用程序

Detect if web application is opened in outlook-add-in

我正在努力检查我的托管 Web 应用程序是否由浏览器或 Outlook 2013/2016 客户端打开。

我有一个 Web 应用程序,它必须在浏览器和 Outlook 2013/2016 沙盒 iframe 中为用户提供不同的功能。

我的做法

主控制器中有 AngularJS:

$rootScope.isIFrame = false;
if (window.location !== window.parent.location) {
  // The page is in an iframe
  $rootScope.isIFrame = true;
};
$log.debug('isIFrame: ' + $rootScope.isIFrame);

查看Office.context.mailbox.diagnostics.hostName:

Gets a string that represents the name of the host application. A string that can be one of the following values: Outlook, Mac Outlook or OutlookWebApp.