方法一(网页上判断)

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. hibernate一级缓存和快照

    摘自网络: Hibernate中的一级缓存的底层是以Map形式存在的,key是主键,value是对象,所以它的泛型为Map<Serializable,Object>,key的泛型为串行化是 ...

  2. 前后端如何保持长连接?---websocket

    1. pc端的应用,一般会采用前端定时请求后台; 2. app定时去访问后台的话,对用户来说并不友好,会消耗大量的流量,移动端最好的方式就是后台主动向app推送信息; 3. H5提供了一种比较好的方式 ...

  3. java_GC

    垃圾回收1    内存分配    垃圾回收    调用垃圾回收器    对象终结            调用垃圾回收器        System.gc()和Runtime.getRuntime(). ...

  4. Property ‘password’ threw Exception

    问题描述: Maven项目在tomcat启动的时候总是报Propety 'password' threw exception异常时,说明password不对,但核对之后没有问题 解决方案: 核对pas ...

  5. java中的成员变量、静态变量与局部变量

    java中的变量分为成员变量(又叫实例变量).静态变量和局部变量. 1.成员变量 1.1 成员变量(实例变量)是在类中定义的非static修饰的变量,可以不用赋初始值,不同的数据类型有默认的初始值. ...

  6. 对象克隆(C# 快速高效率复制对象另一种方式 表达式树转)

    1.需求 在代码中经常会遇到需要把对象复制一遍,或者把属性名相同的值复制一遍. 比如: public class Student { public int Id { get; set; } publi ...

  7. jmeter配置脚本录制进行抓包并快速分析、定位接口问题

    对于测试人员.开发人员来说,善用抓包工具确实是快速分析和定位问题的一大必备神技,现将配置过程记录如下: 1.打开jmeter后,首先添加一个线程组: 2.线程组可以重新命名按项目名称分类 3.然后在工 ...

  8. [转][C#]压缩解压

    { internal static class Compressor { public static Stream Decompress(Stream source, bool bidiStream) ...

  9. C++Primer第五版——习题答案详解(十)

    习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第11章 关联容器 练习11.3 #include<iostream> #i ...

  10. ado.net调用返回多结果集的存储过程