If Deeplink url does not work, send it to the download page

I need to implement javascript where I can determine if my deep link is working or not. If it works, then it should remain the same, but if it does not work, it should start downloading the file. To do this, I use the timeout function to do this. Here is an example of the code I used.

setTimeout(function () { window.location = "https://itunes.apple.com/appdir"; }, 25);
window.location = "appname://";

But this code works fine on Android and ios, but it poses a problem when it comes to the desktop browser. In the desktop browser, after the correct operation of Deeplink, the timeout function does not stop and is redirected to the download page.

so finally I need some kind of event that can determine if my Deeplink is working or not, so I can set the cleartimeout function to prevent the URL from redirecting to load

+4
source share
2 answers

For desktop browsers, consider using a window blur listener and act accordingly. The Blur listener will tell you if the user has left the tab or browser

window.onblur=()=>{//deeplink check (maybe unsuccessfull?)
window.onfocus=()=>{//deeplink unsucesfull};

}
0
source

I would try with a timestamp expression in timeout.

Something like this (play with the rapids as needed):

var clickedTm = +new date;

setTimeout(function () {
   if (+new date - clickedTm < 600) {
      window.location = "https://itunes.apple.com/appdir"; 
   }
}, 500);

window.location = "appname://";
0
source

Source: https://habr.com/ru/post/1693090/


All Articles