如何检测办公室365中的环境?

时间:2016-03-14 12:12:36

标签: office365 office-js

我有一个带有javascript api的outlook插件,从我的网站我想重定向到应用程序的正确环境,

var isSetSupported = function(Application, version) {
                return window["Office"] && Office.context.requirements && Office.context.requirements.isSetSupported(Application + 'Api', version);
            };

            //heck to return the powerpoint library because isSetSupported returns false for PowerpointApi 1.0| 1.1| 1.2 returns false
            var isPowerpointEnviroment = function() {
                return window.location.search.indexOf('_host_Info=Powerpoint') != -1;
            }

            //heck to return the outlook library because isSetSupported returns false for OutlookApi 1.0| 1.1| 1.2 returns false
            var isOutlookEnviroment = function () {
                return window.location.search.indexOf('_host_Info=Outlook') != -1 || ( window.external &&  window.external.GetContext && typeof window.external.GetContext() == 'object');
            }

            if (isSetSupported("Word", 1.1)) {
                return "wordJs";
            }
            if (isSetSupported("Excel", 1.1)) {
                return "excelJs";
            }
            if (isOutlookEnviroment()) {
                return "outlookJs";
            }
            if (isPowerpointEnviroment()) {
                return "powerpointJs";
            }

            return "webApp";

关于本地机器的前景它的工作方式是这样的,但对于office365的前景它不起作用。

1 个答案:

答案 0 :(得分:2)

什么是“Office.context.requirements”?它返回了什么?它甚至没有作为Office.context的属性/对象在API引用中列出:https://msdn.microsoft.com/en-us/library/office/fp161104.aspx

无论如何,对于Outlook,您需要访问Office.context.mailbox.diagnostics对象,并阅读hostname和hostVersion属性:https://dev.outlook.com/reference/add-ins/Office.context.mailbox.diagnostics.html