如果未安装,则将移动用户重定向到应用或商店

时间:2018-03-30 02:01:15

标签: javascript mobile

我希望iOS / Android能够在我的应用程序安装在手机上时使用我的应用程序打开我的域名(例如http://somedomain.com),或者转到app / play store链接应用程序,如果没有。

我读过可以为此创建一个唯一的协议后缀,所以我假设一个JavaScript可以完成这项工作吗?

这可能是什么方法?

试过这个,但没有奏效: 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?

1 个答案:

答案 0 :(得分:0)

<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>