首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果未安装,则将移动用户重定向到应用程序或商店

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

Stack Overflow用户
提问于 2018-03-30 10:01:15
回答 1查看 169关注 0票数 1

每当我的应用程序安装在手机上时,我希望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?

EN

回答 1

Stack Overflow用户

发布于 2018-04-07 02:41:23

代码语言:javascript
复制
<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>
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49567464

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档