方法一(网页上判断)

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. web-msg-send 学习 http://www.workerman.net/web-sender

    WEB消息推送框架 web-msg-sender是一款web长连接推送框架,采用PHPSocket.IO开发,基于WebSocket长连接通讯,如果浏览器不支持WebSocket则自动转用comet推 ...

  2. cordova文件传输系统插件使用:cordova-plugin-file-transfer

    1. 添加插件:cordova plugin add cordova-plugin-file-transfer 2. 调用方法: var fileTransfer = new FileTransfer ...

  3. 关于IE无法访问本机网络的问题

    多次遇到IE无法访问本机站点的情况,比如架设了一个花生壳,所有人都可以访问,唯独本机不行(服务器),还需要把这个域名加入信任站点,这TMD什么情况.今天又遇到访问本地restful service,用 ...

  4. docker lamp

    可以直接使用官方镜像搭建LAMP环境从官方下载PHP+Apache镜像和MySQL两个镜像来组成(如:php:7.2.3-apache-stretch和mysql:5.7.21)docker pull ...

  5. PythonStudy——函数的参数 Function argument

    形参与实参 # 参数介绍:# 函数为什么要有参数:因为内部的函数体需要外部的数据# 怎么定义函数的参数:在定义函数阶段,函数名后面()中来定义函数的参数# 怎么使用函数的参数:在函数体中用定义的参数名 ...

  6. java_字段声明

    多字段继承,为避免混淆,simple name与qualified name的使用 package java20180129_1; interface Frob { float v=2.0f; } c ...

  7. day45 jQuery

    在用js写代码时,会遇到一些问题: window.onload 事件有事件覆盖的问题,因此只能写一个事件. 代码容错性差. 浏览器兼容性问题. 书写很繁琐,代码量多. 代码很乱,各个页面到处都是. 动 ...

  8. pac4j探索(一)之buji-pac4j shiro整合Cas实现单点登录

    https://blog.csdn.net/hxm_code/article/details/79181218 https://blog.csdn.net/hxm_code/article/detai ...

  9. signapk

    signapk工具可以实现对安卓ROM和安卓应用进行签名.在安卓DIY与安卓ROM制作中作用是非常大的.可以使用其对经过自己DIY修改美化后的应用进行签名或对制作好的安卓ROM卡刷包进行签名.让我们做 ...

  10. MyEclipse 10 + OsChina GIt项目托管

    环境:Egit+MyEclipse 10,此教程默认MyEclipse 10和Egit都已经配置好. 1.注册OsChina Git账号,网址:http://git.oschina.net/,具体注册 ...