1

I'd like to have iOS/Android to open URLs from my domain (e.g. http://somedomain.com) with my app whenever the app is installed on the phone, or to go to app/play store links to the app if not.

I read it is possible to create a unique protocol suffix for this so I assume a JavaScript can do the job?

What could be the right approach for this?

Tried this but didn't work: How to redirect the user to a mobile app or a website on click of a hyperlink sent in an email? Should it need to be handled on server-side using PHP?

evul
  • 45
  • 8

1 Answers1

-1
<script>
/*$(document).ready(function () {
  console.log('Redirect to APP');
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        //return "Windows Phone";
        console.log('Windows Phone');
    }

    if (/android/i.test(userAgent)) {
        //return "Android";
        console.log('Android');
        var now = new Date().valueOf();
        setTimeout(function () {
            if (new Date().valueOf() - now > 100) return;
            window.location = "https://play.google.com/store/apps/";
        }, 25);
        window.location = "appname://";
    }


    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        //return "iOS";
        console.log('iOS');
        var now = new Date().valueOf();
        setTimeout(function () {
            if (new Date().valueOf() - now > 100) return;
            window.location = "https://itunes.apple.com/appdir";
        }, 25);
        window.location = "appname://";
    }
});*/
</script>
evul
  • 45
  • 8
  • Welcome to Stack Overflow! But this code is commented and does nothing... In any case you need to explain it. – MappaM Mar 22 '21 at 10:28