How to check if the SharePoint site is opened from MS teams or not

AHMAD ABDELHAFEZ ELAGAMY 1 Reputation point
2022-10-17T07:37:14.993+00:00

I have a SharePoint site and added it to Teams as an app , and it works fine. I want to check on a specific page of this site if the page is now running from MS Teams or not . Is it possible to do that with jQuery-JavaScript or is it applicable or not? .

Thank you in advance .

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,047 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,600 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,663 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,836 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. JimmySalian-2011 41,916 Reputation points
    2022-10-17T07:51:25.913+00:00

    Hi,

    You can check via the Teams App Usage via the portal - app-usage-report and this is also points to the analytics and reporting teams-reporting-reference
    Hope this helps.
    JS

    ==
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


  2. Nivedipa-MSFT 2,806 Reputation points Microsoft Vendor
    2022-10-17T09:52:55.817+00:00

    @AHMAD ABDELHAFEZ ELAGAMY -
    There doesn't seem to be any way available in JQuery/Javascript to check if the SharePoint site is opened from MS teams or not

    Using below powershell command you can get the SharePoint site URL and then you can add your custom logic to check if the URL is available in that list or not.

    Get-UnifiedGroup –Filter {ResourceProvisioningOptions -eq "Team"} |  
     Select DisplayName,SharePointSiteUrl |  
     Export-CSV ./TeamsSPOUrl.csv -NoTypeInformation  
    

    When a team is created, a Microsoft 365 group is created to manage team membership. So, we can use Get-UnifiedGroup cmdlet with ResourceProvisioningOptions filter to retrieve the SharePoint URLs for Teams-enabled Microsoft 365 groups.

    The below given code exports Teams and their associated SharePoint site URL to TeamsSPOUrl.csv file.

    Get-UnifiedGroup –Filter {ResourceProvisioningOptions -eq "Team"} |  
     Select DisplayName,SharePointSiteUrl |  
     Export-CSV ./TeamsSPOUrl.csv -NoTypeInformation  
    

    To run the Get-UnifiedGroup cmdlet, you need to connect to Exchange Online PowerShell module.

    Ref Doc: https://learn.microsoft.com/en-us/powershell/module/exchange/get-unifiedgroup?view=exchange-ps

    Thanks,

    Nivedipa

    ------------------------------------------------------------------------------------------------------------------------

    If the response is helpful, please click "Mark as Best Response" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.


  3. Paul de Jong 716 Reputation points
    2022-10-17T13:18:29.07+00:00

    Perhaps check out the user-agent? It contains Teams/1.5... when loading a site via Teams.

    0 comments No comments