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 365 and Office SharePoint Development
Microsoft Teams Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft Teams Microsoft Teams for business Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. JimmySalian-2011 42,486 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 3,646 Reputation points Microsoft External Staff Moderator
    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 806 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.