如何用js检测手机是否安装某个app

//html代码中 的 a 标签,以微信为例,默认的是调用weixin scheme,去打开本机的微信,如果没有则跳转到相应连接
    <a href="weixin://" class="btn-download">立即打开</a>
  
    // 为btn-download 绑定事件,如果在500ms内,没有解析到协议,那么就会跳转到下载链接 
     var appstore, ua = navigator.userAgent;
        if(ua.match(/Android/i)){ 
            appstore = 'market://search?q=com.singtel.travelbuddy.android';
        }
        if(ua.match(/iphone|ipod|ipad/)){
            appstore = "https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8&ign-mpt=uo%3D4"; 
        }
        function applink(fail){  
            return function(){  
                var clickedAt = +new Date;  
                // During tests on 3g/3gs this timeout fires immediately if less than 500ms.  
                setTimeout(function(){  
                     // To avoid failing on return to MobileSafari, ensure freshness!  
                      if (+new Date - clickedAt < 2000){  
                          window.location = fail;  
                      }  
                }, 500);      
            };  
        }  
        $('.icon-download, .btn-download')[0].onclick = applink(appstore);

  

转载于:https://www.cnblogs.com/binmengxue/p/7495079.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值