-1

How to open a mobile or desktop app with JavaScript from the browser?

A perfect example of what I want to achieve is what Whatsapp and Telegram do when they manage to run their mobile or desktop apps after a click on a website button.

  • Whatsapp (A click on Continue to Chat will open the WhatsApp app); enter image description here

  • Telegram (A click on VIEW IN TELEGRAM will open the Telegram app); enter image description here

Gnopor
  • 587
  • 9
  • 16
  • [This](https://stackoverflow.com/a/3057617/14577449) answer to a similar question might help you. – Juhuja Jan 30 '23 at 11:59
  • 2
    https://en.wikipedia.org/wiki/Mobile_deep_linking – CBroe Jan 30 '23 at 12:01
  • 4
    An application can register itself for a particular protocol. And what happens here is not that the website requests to open a particular application, but an "action" for a particular protocol is requested. And the browser suggests to do that "action" with the application which registered for that protocol. – t.niese Jan 30 '23 at 12:03
  • 1
    There really is no reliable way to do this. It works as @t.niese says, but also depends on the permissions the user have given the apps on their phone. And it probably wont work if the website is visited through an in-app browser, like Facebook tends to do. – Levi Jan 30 '23 at 13:53
  • Thank you! @juhuja They talk about a windows specific solution but I am looking for a more generic one. – Gnopor Jan 30 '23 at 14:08
  • @Gnopor You can't open an arbitrary program on client's computer, if that's what you are asking. – gre_gor Jan 31 '23 at 08:09

2 Answers2

0

Use Windows.open(app://,"_blank","location=yes)

kishore
  • 9
  • 2
  • And how exactly is this supposed to be used? This isn't even valid syntax. – gre_gor Jan 31 '23 at 08:04
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 01 '23 at 19:31
-1

Example:

<a href="tg://resolve?domain=my_group_username">Open Telegram group</a>
<script>
  document.querySelector("a").addEventListener("click", function(event) {
    if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) {
      event.preventDefault();
      location.href = this.href;
    }
  });
</script>

This code creates a link with the URL tg://resolve?domain=my_group_username, which is the URL scheme associated with the Telegram app. When the link is clicked, the Telegram app will be opened and the user will be taken to the specified group.

Note that this code is specific to the Telegram app and will not work for other apps. Each app has its own custom URL scheme, and you will need to consult the app's documentation to determine what it is and how to use it.

eg: Open the url such as https://t.me/publictestgroup , then open the devtools, check the Elements, click the 「Select an element in the page to inspect it」, choose View in Telegram, and you can see the flow:

<div class="tgme_page_action">
  <a class="tgme_action_button_new shine" href="tg://resolve?domain=publictestgroup">View in Telegram</a>
</div>
nopanic
  • 1
  • 2
  • What is the point of that click event handler? Doesn't `location.href = this.href;` basically happen by default? – gre_gor Jan 31 '23 at 08:07
  • And OP is not asking specifically about Telegram or any other specific app. – gre_gor Jan 31 '23 at 08:23
  • On IOS/Android use Deep links, click [Deep links](https://support.google.com/google-ads/answer/10023042?hl=en#zippy=%2Cfor-android-apps---app-links%2Cfor-ios-apps---universal-links%2Cfor-android-or-ios---custom-schemes) check details. – nopanic Jan 31 '23 at 09:20
  • @gre_gor You are right, My answer is based on PC, and Each APP has different URL scheme, for example, Telegram scheme [Deep Links](https://core.telegram.org/api/links). But on browser we can use : `````` – nopanic Jan 31 '23 at 09:28