How do I launch an external application from the browser like Telegram url links?

百般思念 提交于 2020-03-25 17:54:07

问题


I am trying to recreate the following application launch with telegram when one visits the telegram user profile page. Example: https://t.me/username1

When the page is loaded, it gives an alert box to open the telegram app. How do I recreate this as a URL link on a webpage? Also how are they doing this on page load and where is it in the source code so I can see it?


回答1:


Use tg just like you use mailto

tg://resolve?domain=username1

<a href="tg://resolve?domain=username1">Message me!</a>

To launch it page load, just use the standard DOMContentLoaded and redirect the browser;
document.addEventListener("DOMContentLoaded", function(event) { 
  window.location.href = "tg://resolve?domain=username1";
});


I've searched quite some time to find any documentation, there is one reddit post from 1 year ago, but they only shared the 'source file'.

来源:https://stackoverflow.com/questions/60745924/how-do-i-launch-an-external-application-from-the-browser-like-telegram-url-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!