如何知道 Web 应用程序是在浏览器上访问还是从团队自定义应用程序访问
How to know that web app is access on browser or from teams custom app
我的 Web 应用程序是在 angular 中创建的。我可以检查是否从浏览器或 Teams 自定义应用程序访问 Web 应用程序。
据我所知,此功能可用于在 React 中创建的应用程序。
例子 :-
从“msteams-react-base-component”导入{useTeams};
const [{ inTeams, theme, context }] = useTeams();
以上 inTeams return 布尔值,它指示应用程序是从浏览器访问还是从自定义应用程序访问。
所以我也在 angular 中得到了这个?
可以从msteams-react-base-component中获取函数,很简单:
import * as microsoftTeams from "@microsoft/teams-js";
export const checkInTeams = (): boolean => {
// eslint-disable-next-line dot-notation
const microsoftTeamsLib = microsoftTeams || window["microsoftTeams"];
if (!microsoftTeamsLib) {
return false; // the Microsoft Teams library is for some reason not loaded
}
if ((window.parent === window.self && (window as any).nativeInterface) ||
window.name === "embedded-page-container" ||
window.name === "extension-tab-frame") {
return true;
}
return false;
};
在名为 hostClientType
的 Teams Context 对象上有一个 属性,我认为 is/was 是用来处理这个问题的。它包含像 'web' 和 'desktop' 这样的值,并且它曾经被记录为同一文档的 here but this doc has been updated to remove this property (amongst others). Here is an older 版本,其中包含更多信息。 属性 仍然存在,并且包含此信息,但我不确定为什么将其从文档中删除(可能 属性 已被弃用)。
我的 Web 应用程序是在 angular 中创建的。我可以检查是否从浏览器或 Teams 自定义应用程序访问 Web 应用程序。
据我所知,此功能可用于在 React 中创建的应用程序。 例子 :- 从“msteams-react-base-component”导入{useTeams}; const [{ inTeams, theme, context }] = useTeams();
以上 inTeams return 布尔值,它指示应用程序是从浏览器访问还是从自定义应用程序访问。
所以我也在 angular 中得到了这个?
可以从msteams-react-base-component中获取函数,很简单:
import * as microsoftTeams from "@microsoft/teams-js";
export const checkInTeams = (): boolean => {
// eslint-disable-next-line dot-notation
const microsoftTeamsLib = microsoftTeams || window["microsoftTeams"];
if (!microsoftTeamsLib) {
return false; // the Microsoft Teams library is for some reason not loaded
}
if ((window.parent === window.self && (window as any).nativeInterface) ||
window.name === "embedded-page-container" ||
window.name === "extension-tab-frame") {
return true;
}
return false;
};
在名为 hostClientType
的 Teams Context 对象上有一个 属性,我认为 is/was 是用来处理这个问题的。它包含像 'web' 和 'desktop' 这样的值,并且它曾经被记录为同一文档的 here but this doc has been updated to remove this property (amongst others). Here is an older 版本,其中包含更多信息。 属性 仍然存在,并且包含此信息,但我不确定为什么将其从文档中删除(可能 属性 已被弃用)。