zoukankan      html  css  js  c++  java
  • js检测手机上是否有此APP,有的话打开应用,没有的话跳转到appstore

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

    或者 IOS设备上可以

    1 <meta name="apple-itunes-app" content="app-id=414478124" />
  • 相关阅读:
    和阿文一起学H5-文字云制作
    uml与数据库设计
    设计模式——面向对象设计原则
    koajs框架解决的问题
    mongodb
    javascript 获取select选中text,2种方法
    带参数跳转
    express表单提交和参数接收4种方式
    ejs模版的4种输出方式
    nodejs事件
  • 原文地址:https://www.cnblogs.com/ming-os9/p/8932490.html
Copyright © 2011-2022 走看看