方法一(网页上判断)

if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  var loadDateTime = new Date();
  window.setTimeout(function() {
   var timeOutDateTime = new Date();
   if (timeOutDateTime - loadDateTime < 5000) {
    window.location = "要跳转的页面URL";
   } else {
    window.close();
   }
  },
  25);
  window.location = "www://?param1=xxx&param2=xxx ";//与APP约定的一个协议URL
 } else if (navigator.userAgent.match(/android/i)) {
  var state = null;
  try {
   state = window.open("www://?param1=xxx&param2=xxx ", '_blank');//与APP约定的一个协议URL
  } catch(e) {}
  if (state) {
   window.close();
  } else {
   window.location = "要跳转的页面URL";
  }
 }

方法二

function testApp(url) {
  var timeout, t = 1000, hasApp = true;
  setTimeout(function () {
    if (hasApp) {
      alert('安装了app');
    } else {
      alert('未安装app');
    }
    document.body.removeChild(ifr);
  }, 2000)
  
  var t1 = Date.now();
  var ifr = document.createElement("iframe");
  ifr.setAttribute('src', url);
  ifr.setAttribute('style', 'display:none');
  document.body.appendChild(ifr);
  timeout = setTimeout(function () {
     var t2 = Date.now();
     if (!t1 || t2 - t1 < t + 100) {
       hasApp = false;
     }
  }, t);
}

方法三(APP里判断)

var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
 
 
if(isAndroid){
      function android(){
        window.location.href = "www://?param1=xxx&param2=xxx"; /***打开app的协议,有安卓同事提供***/
        window.setTimeout(function(){
           window.location.href = "http://"; /***下载app的地址***/
        },2000);
      };
if(isiOS){
      function ios(){
        var ifr = document.createElement("iframe");
        ifr.src = "www://?param1=xxx&param2=xxx"; /***打开app的协议,有ios同事提供***/
        ifr.style.display = "none";
        document.body.appendChild(ifr);
        window.setTimeout(function(){
          document.body.removeChild(ifr);
           window.location.href = "http://"; /***下载app的地址***/
        },2000)
      };
}

JS判断手机端是否安装某应用的更多相关文章

  1. js判断手机端操作系统(Andorid/IOS)

    非常实用的js判断手机端操作系统(Andorid/IOS),并自动跳转相应下载界面 androidURL = "http://xxx/xxx.apk"; var browser = ...

  2. js判断手机端操作系统的两种方法

    //判断手机端操作系统(Andorid/IOS),并自动跳转相应下载界面 androidURL ="http://xxx/xxx.apk"; var browser = { ver ...

  3. js判断手机端

    if (window.location.toString().indexOf('pref=padindex') != -1) { } else { if (/AppleWebKit.*Mobile/i ...

  4. 原生js判断手机端页面滚动停止

    var topValue = 0,// 上次滚动条到顶部的距离 interval = null;// 定时器 contactsList = document.getElementById(" ...

  5. js判断手机端操作系统(Andorid/IOS),并自动为链接添加相应下载地址

    <script type="text/javascript"> $(document).ready(function(e) { var u = navigator.us ...

  6. js判断手机端Android手机还是iPhone手机

    /*判断当前设备是平板.安卓.苹果设备*/ <script type="text/javascript"> function fBrowserRedirect(){ v ...

  7. js判断手机端(Android手机还是iPhone手机)

    /** * [isMobile 判断平台] * @param test: 0:iPhone 1:Android */ function ismobile(test){ var u = navigato ...

  8. JS判断手机端和PC端自动跳转

    <script type="text/javascript">     function browserRedirect() {     var sUserAgent ...

  9. js判断手机端和pc端

    var browser = { versions: function() { var u = navigator.userAgent, app = navigator.appVersion; retu ...

随机推荐

  1. hdu5003 Osu!排序实现水题

    Osu! is a famous music game that attracts a lot of people. In osu!, there is a performance scoring s ...

  2. 建筑的永恒之道 (C·亚历山大 著)

    永恒之道 建筑或城市只有踏上了永恒之道,才会生机勃勃. 第1章 永恒之道 它是一个唯有我们自己才能带秩序的过程,它不可能被求取,但只要我们顺应它,它便会自然而然地出现. 质 为了探求永恒之道,我们首先 ...

  3. php读取不到指定的php.ini配置

    新建启动脚本 启动时指定路径 解决方案一:修改  /etc/init.d/php-fpm 文件 1 # 在这行命令上添加 指定的配置路径 2 php_opts="--fpm-config $ ...

  4. 第0章 概述及常见dos命令

    计算机发展史 计算机的发展历史有多长?真正意义上的计算机诞生,距今也只有80多年的时间.80年,对于每一个人来说,是很长的时间,但对于整个历史来说,只是短短的一瞬间. 从第一代电子计算机的发明,到今天 ...

  5. 网络之 Iptables总结

    查询iptables -L 默认 filter表iptables -L -t filteriptables -L -t natiptables -L -t mangle Filter表service ...

  6. Lucene的基本使用

    1.了解搜索技术 2.搜索引擎的原理 索引:类似于书的目录 3.实现搜索技术的方式 方式1:数据库搜索 利用SQL语句进行模糊搜索: select * from items where title l ...

  7. Docker三大核心概念及DockerToolBox安装

    一.核心概念 Docker大部分操作都围绕三大概念——镜像.容器和仓库展开. 1.Docker镜像 Docker镜像类似于虚拟机镜像,可以将它理解为一个只读的模板.镜像是创建Docker容器的基础. ...

  8. Xtrabackup2.4.8备份、还原、恢复Mysql5.7.19实操(网络拷贝)

    环境:CentOS 6.7  + Mysql 5.7.19 + Xtraback 2.4.8 innobackupex常用参数: --user=USER 指定备份用户,不指定的话为当前系统用户 --p ...

  9. 性能监控扩展篇(grafana + influxdb + telegraf)

    之前已经说过了自己写sh脚本监控,我看有人评论了说用telegraf进行数据收集,于是乎去研究了下,感觉还可以,不过磁盘io的的表个人感觉有些美中不足,并未直接给出读写速率的情况,可能是研究时间太短, ...

  10. js获取浏览器内核判断终端(是QQ打开还是QQ浏览器打开)

    var browser ={ versions: function() { var u = navigator.userAgent, var ua = navigator.userAgent.toLo ...