js判断请求是android还是ios,并判断手机是否存在一个特定的程序,如果存在就打开,不存在就下载

来源:互联网 发布:黑搜对淘宝号有影响吗 编辑:程序博客网 时间:2024/04/30 05:25

 window.userAgentPlatform = 'PC';
 window.referSite = '';
 window.appProtocolLink = "";

 function getQueryString(name) {
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  var r = window.location.search.substr(1).match(reg);
  if (r != null)
   return unescape(r[2]);
  return "";
 }

 /**��ȡurl�ö��ַ����ַ�**/
 function GetParam(paramName) {
  paramValue = "";
  isFound = false;
  if (this.location.search.indexOf("?") == 0
    && this.location.search.indexOf("=") > 1) {
   arrSource = unescape(this.location.search).substring(1,
     this.location.search.length).split("&");
   i = 0;
   while (i < arrSource.length && !isFound) {
    if (arrSource[i].indexOf("=") > 0) {
     if (arrSource[i].split("=")[0].toLowerCase() == paramName
       .toLowerCase()) {
      paramValue = arrSource[i].split("=")[1];
      isFound = true;
     }
    }
    i++;
   }
  }
  return paramValue;
 }

 // ���referSite�ж���Դ��΢����΢�ţ�
 // ���isappinstalled��ֵ�ж���ת�����ҳ��
 function initFunc() {
  var divc = document.getElementById('guide');
  if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
   divc.setAttribute("class", "sinaweiboiPhone");
   userAgentPlatform = 'iPhone';

  } else {
   divc.setAttribute("class", "sinaweiboAndroid");
   userAgentPlatform = 'Android';
  }

  var thisURL = document.URL;
  var id = GetParam("id");

  var isappinstalled = getQueryString("isappinstall");
  
  if (isappinstalled == '1') {
  
   if (userAgentPlatform == "iPhone") {
    setTimeout(function() {
     window.location = "=" + id;
    }, 2000);
   } else if (userAgentPlatform == "Android") {
    setTimeout(function() {
    
     window.location = "?id="+id;
    }, 200);
   }

  }/*else if(isappinstalled == '0'){
  } */else {
  
   if(!navigator.userAgent.match(/(MicroMessenger);?/i))
   {
    
    if (userAgentPlatform == "iPhone")
    {
     document.location.href = "plist地址";
    }
    else if (userAgentPlatform == "Android")
    {
     document.location.href = "软件地址";
    }
   
   }
   
  }
  
 }

 if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", initFunc, false);
 } else {
  window.onload = initFunc;
 }

0 0
原创粉丝点击