【问题标题】:Redirect mobile users to app or store if not installed如果未安装,将移动用户重定向到应用程序或商店
【发布时间】:2018-03-30 02:01:15
【问题描述】:

我想让 iOS/Android 在手机上安装应用程序时使用我的应用程序从我的域(例如http://somedomain.com)打开 URL,或者如果没有,则转到应用程序/播放商店链接到应用程序.

我读到可以为此创建一个唯一的协议后缀,所以我认为 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?

【问题讨论】:

    标签: javascript mobile


    【解决方案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>
    

    【讨论】:

    • 欢迎来到 Stack Overflow!但是这段代码被注释了,什么也没做……无论如何你需要解释一下。
    猜你喜欢
    • 2019-06-18
    • 2019-10-15
    • 2012-11-11
    • 2019-05-04
    • 2020-06-23
    • 2021-08-21
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多