h5 扫描二维码打开app和点击下载功能的实现

window.onload = function () {
   jumpToapp()
}
var browser = {
  isAndroid: function () {
    return navigator.userAgent.match(/Android/i) ? true : false;
  },
  isMobileQQ: function () {
    var ua = navigator.userAgent;
    return /(iPad|iPhone|iPod).*? (IPad)?QQ\/([\d\.]+)/.test(ua) ||
    /\bV1_AND_SQI?_([\d\.]+)(.*? QQ\/([\d\.]+))?/.test(ua);
},
  isIOS: function () {
    return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
},
  isWx: function () {
    return navigator.userAgent.match(/micromessenger/i) ? true : false;
},
  isChrome: function () {
    return navigator.userAgent.match(/chrome/i) ? true : false;
  }
};
var createIframe = (function () {
  var iframe;
  return function () {
      if (iframe) {
        return iframe;
      } else {
        iframe = document.createElement('iframe');
        iframe.style.display = 'none';
        document.body.appendChild(iframe);
        return iframe;
      }
  }
})()

var jumpToapp = function () {
  var isAndroid = function () {
    return navigator.userAgent.match(/Android/i) ? true : false;
  }
  var isIOS = function () {
    return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
  }
if (isIOS()) {
  window.location.href = "sxz://sxz.com";//伪协议scheme
} else if (isAndroid()) {
  var ifr = document.createElement('iframe');
  ifr.src = "sxz://sxz.com";//伪协议scheme
  ifr.style.display = 'none';
  document.body.appendChild(ifr);
  }
 }
$('#open_app').click(function () {
  openApp();
})

var openApp = function () {
  if (browser.isIOS()) {
    window.location.href = "ios下载地址";
  } else if (browser.isAndroid()) {
    window.location.href = "安卓下载地址";
 }

 

 

posted @ 2018-01-08 22:55  Lonely,lonelyBurning  阅读(3004)  评论(0编辑  收藏  举报