我正在努力检查我的托管 Web 应用程序是否由浏览器或 Outlook 2013/2016 客户端打开。
这是我的方法:
/**
* Check if the app is running in outlook
*/
$rootScope.isOutlook = false;
$(document).ready(function () {
try {
Office.initialize = function() {
var hostType = Office.context.mailbox.diagnostics.hostName;
if (hostType === "Outlook" || hostType === "Mac Outlook" || hostType === "OutlookWebApp") {
$rootScope.isOutlook = true;
}
};
} catch (e) {
if (e instanceof TypeError) {
// catch error if web app is opened in browser.
console.log('Not in office context! Generated error: ' + e);
}
}
});
$log.debug('isOutlook: ' + $rootScope.isOutlook);
该函数本身就像一个魅力,但我无法摆脱'Uncaught TypeError'。它一直在我的浏览器控制台中向我抛出这个 Uncaught TypeError:
Uncaught TypeError: window.external.GetContext is not a function