zoukankan      html  css  js  c++  java
  • html5页面js判断是否安装app,以及判断是否在app内部打开html5页面

    一、html5页面js判断是否安装app
    目前还不能通过浏览器直接判断是否安装app
    通过谷歌参考别人的方式和测试
    我们知道安装了某个app后通过scheme跳转协议(引荐:http://www.jianshu.com/p/eed01a661186)进入到app
    没有安装时点击链接是无效的
     
    所以通过点击链接后到执行进入app之间的时间差来判断是否安装app 
    1、下面只是处理了安卓系统时
      
       if (navigator.userAgent.match(/android/i) ){
        var nowTime = new Date().valueOf();
        setTimeout(function(){  
             var launchTime = new Date().valueOf() - nowTime;
             if(launchTime < 28){     //28是调试估算出来的打开本地app基本需要的时间
                  window.location = "/phone/forward/app_download_redirect"; //下载app页面
             }
        },25);
        window.location="mysppscheme://";//自己定义的scheme协议
      } 
    2、iphone用一样的原理实现测试有效
     
    3、weixin分享里面的页面会在url添加变量isappinstalled
     isappinstalled=1的时候代表安装了app,值为0的时候代表没有安装
     微信屏蔽了url scheme直接跳转,所以weixin分享页通过提示浏览器打开
     再根据之前的isappubstalled值来判断是否安装app
     
    var isWeixin = navigator.userAgent.match(/MicroMessenger/ig); //是否在微信
    var appInstalled = document.location.href.indexOf("isappinstalled=1")>=0; //是否安装app
     
    上面方式是我通过谷歌看大家提出的方式和自己的测试唯一还没出现问题的方式
    当然后续有问题会继续更新
     
    二、判断是否在app内部打开html5页面
    判断当前页面是否在app内部打开,单纯的web前端还不能解决
    需要客户端对userAgent添加自己app相关的字段
    (useragent设置Android:http://www.jincon.com/archives/354/)
     
    var userAgent = navigator.userAgent.toLowerCase(), //获取userAgent
         isInapp = userAgent.indexOf("sunyuki")>=0;//查询是否有相关app的相关字段
     
  • 相关阅读:
    Shared Memory in Windows NT
    Layered Memory Management in Win32
    软件项目管理的75条建议
    Load pdbs when you need it
    Stray pointer 野指针
    About the Rebase and Bind operation in the production of software
    About "Serious Error: No RTTI Data"
    Realizing 4 GB of Address Space[MSDN]
    [bbk4397] 第1集 第一章 AMS介绍
    [bbk3204] 第67集 Chapter 17Monitoring and Detecting Lock Contention(00)
  • 原文地址:https://www.cnblogs.com/guoshan/p/6835231.html
Copyright © 2011-2022 走看看