简体   繁体   English

如何知道 web 应用程序可在浏览器或团队自定义应用程序上访问

[英]How to know that web app is access on browser or from teams custom app

My web application is created in angular.我的 web 应用程序是在 angular 中创建的。 Can I check whether web application is accessed from browser or Teams custom apps.我可以检查是否从浏览器或团队自定义应用程序访问 web 应用程序。

As I know this features is available for app which are created in react.据我所知,此功能可用于在 react 中创建的应用程序。 example:- import { useTeams } from "msteams-react-base-component";示例:- 从“msteams-react-base-component”导入 { useTeams }; const [{ inTeams, theme, context }] = useTeams(); const [{ inTeams, 主题, 上下文}] = useTeams();

Above inTeams return boolean, which tells whether app is accessed from browser or custom app.上面的 inTeams 返回 boolean,它告诉应用程序是从浏览器还是自定义应用程序访问。

So I get this in angular as well?所以我也在 angular 中得到这个?

You can take the function from msteams-react-base-component, it's very simple:您可以从 msteams-react-base-component 获取 function,非常简单:

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;
};

Source 资源

There is a property on the Teams Context object called hostClientType , which I think is/was meant to deal with this. Teams Context object 上有一个名为hostClientType的属性,我认为它是/应该处理这个问题。 It contains values like 'web' and 'desktop', and it used to be documented here but this doc has been updated to remove this property (amongst others).它包含诸如“web”和“desktop”之类的值,它曾经在此处记录,但此文档已更新以删除此属性(以及其他属性)。 Here is an older version of the same doc which contains more info.这是同一文档的版本,其中包含更多信息。 The property still exists, and it holds this info, but I'm not sure why it was removed from the documents (perhaps the property has been deprecated).该属性仍然存在,并且包含此信息,但我不确定为什么将其从文档中删除(也许该属性已被弃用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在AWS中托管动态AngularJS Web应用并在浏览器中访问它 - How to host a dynamic AngularJS web app in AWS and access it in browser 将链接从移动网络浏览器迁移到移动应用程序 - Migrate link from mobile web browser to mobile app Javascript:如何通过网络应用程序使用Google API访问“特定用户”数据? - Javascript: how to access *specific user* data with Google API from web app? 我不知道如何组织使用基于组件的Web框架的Web应用程序 - I don't know how to organize a web app that uses component based web framework 管理从控制台应用程序到Azure上的Web API的访问 - Managing access from a Console App to a Web API on Azure 从网络应用访问Google Cloud端点时出现“未配置访问” - “Access not configured” when accessing google cloud endpoints from web app 可以使用Ionic创建Web浏览器应用程序吗? - Can a web browser app be created with Ionic? 如何从自定义Android应用启动uber eats应用 - How to Launch uber eats app from a custom Android app 网页浏览器刷新时,Angular应用无法正常工作 - Angular app not working when web browser refreshed 验证站点/应用程序以访问Web API服务 - Authenticate a site/app to access a Web API Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM