Integrating Web Pages into MS Teams: Seeking Guidance

Fabian Rico 0 Reputation points
2024-10-01T11:53:34.4433333+00:00

I’m designing a web page for a chat group in MS Teams, and I previously had a link that would open content directly in the MS Teams environment.

Currently, when someone clicks the button on the tab, the web page opens in a new browser window, which isn’t what I want.

How can I configure it so that the page opens directly within MS Teams instead of a web browser? Thanks for your help!

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.
3,250 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sayali-MSFT 2,416 Reputation points Microsoft Vendor
    2024-10-03T12:27:15+00:00

    To ensure that your web page opens directly within the MS Teams environment instead of a new browser window, you need to configure your tab to use the microsoftTeams JavaScript library. Here are the steps you can follow:

    1. Initialize the Microsoft Teams library: Ensure that you have included the Microsoft Teams JavaScript SDK in your web page and initialized it properly. This can be done by calling microsoftTeams.initialize().
    2. Use the microsoftTeams library to open URLs: Instead of using standard HTML links, use the microsoftTeams library to open URLs within the Teams environment. You can use the method microsoftTeams.app.openLink to achieve this.

    Here is an example of how you can do this:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" type="text/css" href="/styles/msteams-16.css"/>
        <link rel="stylesheet" type="text/css" href="/styles/custom.css"/>
        <script
              src="https://res.cdn.office.net/teams-js/2.0.0/js/MicrosoftTeams.min.js"
              integrity="sha384-QtTBFeFlfRDZBfwHJHYQp7MdLJ2C3sfAEB1Qpy+YblvjavBye+q87TELpTnvlXw4"
              crossorigin="anonymous">
        </script>
        <script>
            microsoftTeams.app.initialize().then(() => {
            });
            function createLink() {
                var appId =  "<%-microsoftAppId%>";
                var baseUrl =  "<%-baseUrl%>";
                // Passing the values and encoding the url while implementing the deeplink from tab
                let url = "https://teams.microsoft.com/l/stage/"+appId+"/0?context={\"contentUrl\":\""+baseUrl+"/content\",\"websiteUrl\":\""+baseUrl+"/content\",\"name\":\"DemoStageView\"}";
                alert("URL - " + url);
                microsoftTeams.app.openLink(url);
            };
        </script>
    </head>
    <body class="theme-light">
        <div class="surface">
            <div class="panel">
                <div>
                    <label for="tabChoice"></label>Click on the button to view the stage view from deeplink:
                    <button onClick="createLink()">Execute deeplink</button>
                </div>
            </div>
        </div>
    </body>
    </html>
    

    In this example, when the button is clicked, the createLink() function is called, which uses the microsoftTeams.app.openLink method to open the specified URL within the Teams environment.

    Make sure to replace "url" with the actual URL you want to open.

    Reference document:-
    1.https://video2.skills-academy.com/en-us/javascript/api/%40microsoft/teams-js/app?view=msteams-client-js-latest#@microsoft-teams-js-app-openlink

    2.https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/200bb8ab07a18fb82fb94cc30e64c5dd5d036a2d/samples/tab-stage-view/nodejs/server/views/sampleTab.ejs#L22

    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.