0

The question concerns js more than the specific task of Telegram determination.

In the normal case, on a web page there is code that, in case when an app is installed (in our case it's Telegram), sends the user to the app at once.

<script type="text/javascript">
    var url = "tg://resolve?domain=";
        setTimeout(function() {
            window.location = url;
        }, 100);
    </script>

There is also code that, for example, will also open a page in a browser after some time.

<script type="text/javascript">
    var now = new Date().valueOf();
    setTimeout(function () {
        if (new Date().valueOf() - now > 200) return;
        window.location = "https://itunes.apple.com/";
    }, 25);
    window.location = "tg://resolve?domain=";
</script>

Meanwhile, we would like only one of the options to work - either an app or a web page should open (if the app isn't installed).

In this regard, there is a question if we can somehow monitor the following developments: - the user left the page but didn't open it (some events that can prompt that the user doesn't interact with the page). We mean that in this case the user opened Telegram and it is installed. - if it's possible, to note the time during which the user didn't interact with the page (in case when the user went to Telegram and after some time - e. g., a few minutes - came back to the browser on our page).

So, the algorithm is like this: if Telegram is installed, then we suppose the tab with our web page will be open, and no actions will be performed on the page - for quite long, at least 20 seconds. if Telegram is not installed, then the user will either close the web page or will somehow interact with it (scroll, click, etc.).

S.Znobihin
  • 1
  • 1
  • 2
  • 1
    Possible duplicate of [simplest cross-browser check if protocol handler is registered](https://stackoverflow.com/questions/24779312/simplest-cross-browser-check-if-protocol-handler-is-registered) – str Jul 24 '18 at 08:20

0 Answers0