Almaz Gimaev
Almaz Gimaev

Reputation: 81

How can I make a website link open NOT in the Telegram app's built-in browser?

I am developing a website. The problem is that when opening the website link from the mobile Telegram app, it opens in the app's built-in browser. This browser has its own limitations that are causing problems for me. How can I make the links open in the phone's default browser instead?

<script>
    console.log("start")
    if (navigator.userAgent.indexOf("Telegram") != -1) {
        console.log("navigator.userAgent.indexOf('Telegram') != -1")
      window.location.replace("https://traffic-simulation.ru");
      console.log("window.location.replace('https://traffic-simulation.ru');")
    }
</script>

so how can I make a website link open NOT in the Telegram app's built-in browser?

Upvotes: 8

Views: 4454

Answers (2)

0xManjeet
0xManjeet

Reputation: 63

This works:

   if (window.TelegramWebview) {
        const url = window.location.href;
        const chromeUrl = `intent://${url.replace(/^https?:\/\//, '')}#Intent;scheme=https;end`;
        window.location.href = chromeUrl;
    }

Upvotes: 0

James M
James M

Reputation: 21

<script src="https://telegram.org/js/telegram-web-app.js"></script> <button onclick="javascript:Telegram.WebApp.openLink('https://www.google.com/');">Click Me</button>

How I did it with a button.

https://github.com/telegram-mini-apps-dev/vanilla-js-boilerplate/tree/master

Upvotes: 1

Related Questions